Thread: Makefile with libconfig

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    4

    Smile 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 ;-)

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    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

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    4
    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
    Last edited by TheDestroyer; 11-09-2009 at 07:45 AM.

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    4
    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! :'(

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    4
    Thank you for caring!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile help please
    By TriKri in forum C++ Programming
    Replies: 3
    Last Post: 09-24-2009, 12:36 AM
  2. Replies: 2
    Last Post: 08-11-2009, 06:45 AM
  3. Building a project using a Makefile
    By starcatcher in forum Windows Programming
    Replies: 2
    Last Post: 11-23-2008, 11:50 PM
  4. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 03:32 PM
  5. about Makefile and Macro
    By tom_mk in forum C++ Programming
    Replies: 1
    Last Post: 09-18-2003, 01:07 PM