1

I'm working with Embarcadero XE8 C++ builder 32 bit.

I was adding a library to my program for solving the Unresolved external error.

When I added the library I got the error as in the title. So I searched the web and found this topic on stackoverflow: Linker error "contains invalid OMF record"

As it says the COFF2OMF tool, CAN work. Sadly it didn't work for me, I give a 7mb library file, when I convert it with the tool it's only 41kb... so I guess the convertion failed. When I add the converted files to my program it just ignores it and still says the unresolved external error.

So how can I get my library working with my C++ builder?

Community
  • 1
  • 1
Bart
  • 717
  • 1
  • 9
  • 28

1 Answers1

2

A little background:

Libraries need to be compiled with the same kind of tool as the application you are trying to make, because every compiler does things a wee bit differently. Most libraries for Windows are compiled with the MVSC (Microsoft Visual Studio Compiler).

You're using the Embarcardero Compiler, which means that the MVSC libraries are incompatible (you may have noticed that ;)).

You have multiple options.

  1. If you can, get the source of the library and compile it with your own compiler. That way the chance to succeed is the highest.
  2. I may be mistaken since it's been a while, however I believe there's a tool called implib which takes the shared library (.dll) and generates an Embarcardero-style .lib from that for use in your project.
  3. Use COFF2OMF to convert the static library. And even if the file size is strange, do at least try it.
  4. Try the LoadLibrary function call. This one requires you to map the functions you need manually, however you get around using the .lib.

Good luck.

Refugnic Eternium
  • 4,089
  • 1
  • 15
  • 24
  • 1. How can I get the source? just opening the file with notepad and copy paste it? and how can I compile a library? 2. Not sure if I have the .dll format of the library have to check that. 3. Done that didn't work. 4. I'll investigate that :) Thanks for the options! – Bart Sep 21 '15 at 13:12
  • @Bart That depends, really. Usually, if it's an open-source library, you can download the source separately from wherever you got the library from (most people don't care about the sources and they can be quite large in comparison, which is why they often don't get shipped together with the binaries). Did you get a bunch of .c/.cpp files with your library? You create a project, select `library`, add the source files, hit 'Build' and cross your fingers. Good luck. :) – Refugnic Eternium Sep 21 '15 at 13:21
  • When I create a new project as Static library(I can't create a normal library), it only gives me an empty Project.lib. I cant enter any text anywhere. When I add the dll files it does nothing with them. I cant either add an .lib file. Also if I open the .dll files it's just some random signs that I can't read. – Bart Sep 21 '15 at 13:51
  • Ok I used the `implib` and when I convert the files from .dll to .lib I get new files. When I TDump these files, I get methods like: `??0CEasyPLCHandler@@QAE@ABV0@@Z`, the normal name would be `CEasyPLCHandler`, how can I edit these method names in the library? – Bart Sep 22 '15 at 06:34
  • Maybe this isn't the right answer for my problem, but this could help others with the same problem! Thanks for the help @Refugnic Eternium – Bart Sep 22 '15 at 06:37
  • @Bart TDump and consorts tend to return the mangled names. Compilers mangle the names to make absolutely sure that each name can only exist once (in C++ you have function overloading, meaning you'd get the same name multiple times which is an absolute No-Go). Did the library work in your project? Oh and you're welcome. :) – Refugnic Eternium Sep 22 '15 at 10:54
  • Well I discovered the Visual studio uses other mangling standards compared to C++ builder. So thats my main problem now. I found something about changing the stuff via a def-file but I don't know how the name mangling works specifically. I found this article http://bcbjournal.org/articles/vol4/0012/Using_Visual_C_DLLs_with_CBuilder.htm he gives some examples for VS and C++ builder. But as he mentions in the conclusion, the problem is bigger with methods of objects. – Bart Sep 22 '15 at 11:00