I'm working on a c project where I need to include the IPE library. This is available here, and since I use Windows I download and extract the windows binary package. This provides an 'include' folder with header files, and a 'bin' folder with several .dll files, among them ipe.dll.
From what I understand (for example from here there are three things you need to do to link a library:
- You tell the compiler where to find the library's header files, if they're not in any of its default include-directories.
- You tell the linker to link the library.
- You tell the linker where to find the libary, if its not in one of its default search-directories.
I use Visual Studio 2022, where these things are done in the project settings. Step 1 is easy, once I add the 'include' folder to 'Additional Include Directories' in the project settings it recognizes my #include<ipelib.h>. For step 2 and step 3 however I think I need to link a .lib file, which is not provided anywhere.
Simply only linking the header files and putting the .dll files in my output folder (so skipping step 2 and 3) does not work, this results in loads of LNK2019 'unresolved external symbol' errors.
I tried just linking the ipe.dll file (add ipe.dll in Linker/Input/Additional Dependencies) but when building I get this error: Error LNK1107 invalid or corrupt file: cannot read at 0x340 CGALTest C:\Program Files\IPE\ipe-7.2.26\bin\ipe.dll
. This approach doesn't seem right with what I know about .dll and .lib files.
However maybe this is the way to go and this corrupt file error is caused by the following, mentioned on this page:
C mandates that it must be compiled with the same compiler that was used to compile Ipe. If you use the binary Ipe distribution for Windows, that means you have to use the g -mingw-w64-x86-64 toolchain.
I feel like this would give a different error (when actually trying to use the program, not when building it), but I'm not sure so I mention it here for completeness. If this is really the problem I have no idea how to actually use the g -mingw-w64-x86-64 toolchain, but that's a different problem altogether.
I also tried creating the .lib file myself as explained here, but that did not work either. This also feels like it should not be necessary; the IPElib documentation never mentions this.
I realize this is not a very well known library, but I hope someone will know how to help anyway.
CodePudding user response:
You need a .lib to link to. That .lib knows how to dynamically resolve the symbols in the .dll. If you don't have a .lib, you need to dynamically load the symbols yourself.