Recently I decided to try Code::Blocks in conjunction with Mingw32 for a new project (This is on Windows). As I hadn't used Code::Blocks much before, I created a test program, which required linking a static library (dlfcn-win32 in this case).
The linker search path includes the path to libdl.a, and libdl is included in the project's linker settings. However, when I compile this code, I get the error:
1 2 3 4 5
Compiling: main.cpp
Linking console executable: bin\Debug\test.exe
obj\Debug\main.o: In function `main':
C:/**********/main.cpp:8: undefined reference to `dlopen(char const*, int)'
collect2: ld returned 1 exit status
This is strange, as I have linked against libdl. The source code is below:
The actual project will be cross-platform (hence why I'm using Code::Blocks and GNU tools), and will load a shared library at runtime. I'd like to be able to use dlfcn functions on all platforms, and dlfcn-win32 does the trick.
Anyhow, I'll still be linking against other static libraries in the project, namely SDL. I have a feeling this problem is not libdl-specific. I know the library is fine, for I compiled it myself using Mingw.
@Caligulaminus:
GCC only requires -ldl, as -l is the option for adding a library, and 'dl' automatically means 'libdl.a'; Code::Blocks resolves dl, libdl, and libdl.a to '-ldl' in the linker call.
@hanst99:
Unfortunately, I tried and got this:
C:\test\src>g++ -I..\include -o text.exe main.cpp -L..\lib -ldl
C:\Users\Torin\AppData\Local\Temp\ccHLlwwd.o:main.cpp:(.text+0x42): undefined reference to `dlopen(char const*, int)'
collect2: ld returned 1 exit status
Exactly the same error (..\include contains dlfcn.h and ..\lib contains libdl.a). It's getting late, but tomorrow I'll try linking against a different static library to see if the problem is exclusive to win32-dlfcn or not.
I would try compiling and linking in separate commands (g++ -c for compiling, ld for linking), but I know that linking will fail due to the requirement of several standard static libraries that G++ automatically links (it's a pain to list them all).