[CMake] linking main.cpp to class in the same folder.

Mike Jackson mike.jackson at bluequartz.net
Thu Jun 11 08:15:16 EDT 2009


ADD_EXECUTABLE(prog main.cpp class.cpp)

On Thu, Jun 11, 2009 at 7:52 AM, eial at cs.bgu.ac.il<eial at cs.bgu.ac.il> wrote:
>
> hello.
> I've got a class in a folder that I want to run from a main.cpp file, when I compile it, I get a undefined reference to the class's methods.
> do I must create a lib from that single class in order to get the linking working?
> the CMakeList.txt looks like this:
>
> ADD_LIBRARY(lib1 STATIC ${lib1})
> ADD_LIBRARY(lib2 STATIC ${lib2})
>
> #link libs
> target_link_libraries(lib1 ${extlib1})
> target_link_libraries(lib2 ${extlib1} ${extlib2})
>
>
> #list all source files here
> ADD_EXECUTABLE(prog main.cpp)
>
> #need to link to some other libraries
> TARGET_LINK_LIBRARIES(prog lib1 lib2)
>
> main.cpp looks like that:
> #include "Class1.h"
>
> int main(int argc, const char* argv[]) {
>   Class1 cls;
>   cls.Do1();
>   cls.Do2();
>   cls.Do3();
>   cls.close();
>   return 0;
> }
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list