-
Makefile with libconfig
Hello people :),
I'm learning how to using the libconfig library with C++, but I faced a problem, that I want to add the linker command to my makefile source, but I didn't know how! :(
Here is the part of the libconfig manual that gives the information about the command line
"The C++ API classes are defined in the namespace `libconfig', hence the following
statement may optionally be used:
using namespace libconfig;
To link with the library, specify `-lconfig++' as an argument to the linker."
The libconfig library is available in a folder relative to the source file: "libconfig-1.3.2\libconfig.h++".
Actually I don't know how necessary doing this linking stuff is, anyway when I compile I'm getting the following error:
E:/Projects/Netbeans/Deposit/Depositmain.cc:44: undefined reference to `libconfig::Config::~Config()'
E:/Projects/Netbeans/Deposit/Depositmain.cc:44: undefined reference to `libconfig::Config::~Config()'
This error appears only when I try to define an element in the Config object, like:
Config cfg;
but without such a line, no problems appear!
I'm using netbeans for editing, and MinGW for compiling. So please people tell me what file I should open and where I should add the command line, or tell me that the problem is not because of linking.
Thank you in advance for any efforts, even for only reading ;-)
-
when you are compiling with gcc/g++ just add these two options
-L /path of your libconfig library
-l libconfig name of the library without lib and .a/.so
-
Thank you for your answer :)
but should the path be relative to the makefile or to my source file?
Can you please give an example? where the source file and the make file ain't in the same directory?
Thanks :)
-
OK guys, here is the error log:
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/e/Projects/Netbeans/Deposit'
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/deposit.exe
make[2]: Entering directory `/e/Projects/Netbeans/Deposit'
mkdir -p dist/Debug/MinGW-Windows
g++.exe -o dist/Debug/MinGW-Windows/deposit build/Debug/MinGW-Windows/Welcome.o
build/Debug/MinGW-Windows/Welcome.o: In function `main':
E:/Projects/Netbeans/Deposit/Welcome.cc:16: undefined reference to `_imp___ZN9libconfig6ConfigC1Ev'
E:/Projects/Netbeans/Deposit/Welcome.cc:22: undefined reference to `_imp___ZN9libconfig6Config8readFileEPKc'
E:/Projects/Netbeans/Deposit/Welcome.cc:27: undefined reference to `_imp___ZNK9libconfig6Config6lookupEPKc'
E:/Projects/Netbeans/Deposit/Welcome.cc:28: undefined reference to `_imp___ZNK9libconfig7SettingcvlEv'
E:/Projects/Netbeans/Deposit/Welcome.cc:29: undefined reference to `_imp___ZN9libconfig7SettingaSEl'
E:/Projects/Netbeans/Deposit/Welcome.cc:34: undefined reference to `_imp___ZN9libconfig6Config9writeFileEPKc'
E:/Projects/Netbeans/Deposit/Welcome.cc:44: undefined reference to `libconfig::Config::~Config()'
E:/Projects/Netbeans/Deposit/Welcome.cc:44: undefined reference to `libconfig::Config::~Config()'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/MinGW-Windows/deposit.exe] Error 1
make[2]: Leaving directory `/e/Projects/Netbeans/Deposit'
please tell me something to do! :'(
-