0

I've already looked at this SO answer but I cannot seem to find the solution for my case.

I just started working in C++ and CLion. I did a basic test project that includes a header file and the main function then executes a method from the included class - all working just fine, CLion compiler is MinGW.

Now the real project I need to work on integrates a SDK from a vendor written in C++. They do have examples as well. Every time I run them, CLion breaks the build and complains about undefined references... the include file paths are all correct and CMakeList.txt looks like this:

project(test_2)

include_directories("../libraries/bin/headers/")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_EXE_LINKER_FLAGS "")

set(PROJECT_HEADERS

        "../libraries/bin/headers/SDK.h"
        "test.h"
        )
set(PROJECT_SOURCES
        main.cpp
        )

add_executable(test_2 ${PROJECT_SOURCES} ${PROJECT_HEADERS})

the first undefined reference that is listed is the constructor of the SDK class, which is written simply as:

class SDK{
   ...
   SDK();
   ...
}

Any suggestions what the problem is ?

Because of the current situation I cannot reach anybody on their end, so I thought I ask here...

Thanks !

Solution:

the solution was to compile the libs from the .cpp file an make a clean CMakeList file referencing those libs, this then resolved the undefined reference errors.

pete19
  • 333
  • 1
  • 3
  • 17

3 Answers3

0

I'm not fluent in CMake - but you probably have to also link libraries/directories using something like target_link_libraries()/target_link_directories() if using external SDK. Seems to me that you simply tell the compiler "hey, here is my SDK header, do something" but compiler doesn't know where are the symbols for this SDK defined. Here is a little bit of an explanation what is the basic difference between the two, but I recommend checking CMake documentation directly.

c̛̣o̢̥m̯͕̖̠̙͡p͕̭͚͓̮̲ḭ͓͇͔̟̫l̪͈i͉̟̜̺͖͓͉n̮̻̼g͎̩̳̯ ̻̯̹̦̱̠̀w͕̬̜i̖̭̣th̹̠̕ C̙M̩a̲̮̹͉̻̥̥ķ͕̤̭̠͚e̩̙̼ ̫̮is̻̗͈͓͟ f̧̮͓̦u͏̯ͅń̹̣

Tooster
  • 322
  • 3
  • 14
0

I have no clue how the library that you're using is designed, but if there is no definition of the constructor in the header file, it is clearly not header-only. So you either have to link to that library, or add its implementation file (if you have one) to your project so linker gets what you promised. I suggest to look at target_link_libraries to see how to link in CMake (there are more ways to do it though).

Undefined reference error generally means that linker did not find something that was advertised in a header.

0

the solution was to compile the libs from the .cpp file an make a clean CMakeList file referencing those libs, this then resolved the undefined reference errors.

pete19
  • 333
  • 1
  • 3
  • 17
  • please update your Question to Contain your Answer (if you found the answer yourself). That way it's easier for others to find the solution. – A.K. Jul 03 '20 at 07:55