Nominate our 2022 Qt Champions!

Linking problem with C static Library

  • Hi,

    I'm trying to use the classicladder plc as a library in my sample application. Classicladder is developed using the C programming language.

    But when i trying to compile , i got the linking undefined reference error , please help me guys,

    @g++ -Wl,-O1 -Wl,-rpath,/opt/QtSDK/Desktop/Qt/4.8.1/gcc/lib -o checkClassicLadder2 main.o checkclassicladder2.o moc_checkclassicladder2.o -L/opt/QtSDK/Desktop/Qt/4.8.1/gcc/lib -L../../../Downloads/classicladder -lladder -lQtGui -L/opt/QtSDK/Desktop/Qt/4.8.1/gcc/lib -L/usr/X11R6/lib -lQtCore -lpthread
    checkclassicladder2.o: In function checkClassicLadder2::checkClassicLadder2(QWidget*)': checkclassicladder2.cpp:(.text+0x112): undefined reference toClassicLadder_AllocAll()'
    checkclassicladder2.o: In function checkClassicLadder2::checkClassicLadder2(QWidget*)': checkclassicladder2.cpp:(.text+0x3c2): undefined reference toClassicLadder_AllocAll()'
    collect2: ld returned 1 exit status
    make: *** [checkClassicLadder2] Error 1


  • Hi,

    How you .pro file looks?
    Did you add library in which ClassicLadder_AllocAll() is defined?


  • sorry for the late reply

    yes i did add the library which contains the ClassicLadder_AllocAll(). But in the library it declared with the extern keyword

  • What about the C-Library header file?

    You may need the 'external "C" {};' declaration for the methods provided in pure C like this:
    #ifdef cplusplus
    external "C" {

    void C_method1(void);

    #ifdef cplusplus

Log in to reply