Hi,<br><br>I have not been able to find the answer to my current problem so I thought I'd try a new post. Before diving into the details, please be aware that the code I am writing compiles/runs perfectly with a personal Makefile I wrote. <br>
<br>My code is written in C++ and has many different class definitions. To run different simulations some classes may or may not have actual objects created. However, there are other portions of the code that specifically reference functions from nearly all classes (although this code might not actually be used because the object was never created). The linking errors that I am facing arise when I do not make an object of a given class. Other parts of the code need to be aware that the class exists, even if an object was never made. Although this seems like it would be a result of not including the appropriate header files, I assure you they are correct! For some reason, if I do not make an object of a given class cmake "ignores" the class and when it comes time to link everything together I get the following error:<br>
<br>Linking CXX executable collision<br>Output/libOutput.a(Output.cpp.o): In function `Output::Output(std::vector<Ball*, std::allocator<Ball*> >*, std::vector<CollisionObject*, std::allocator<CollisionObject*> >*)':<br>
Output.cpp:(.text+0x379): undefined reference to `SWall::getY2()'<br>Output.cpp:(.text+0x391): undefined reference to `SWall::getX2()'<br>Output.cpp:(.text+0x3a9): undefined reference to `SWall::getY1()'<br>Output.cpp:(.text+0x3c1): undefined reference to `SWall::getX1()'<br>
collect2: ld returned 1 exit status<br>make[2]: *** [collision] Error 1<br>make[1]: *** [CMakeFiles/collision.dir/all] Error 2<br>make: *** [all] Error 2<br><br>PLEASE NOTE: If in my main.cpp file I simply create an SWall object and never use it, the errors go away and everything works perfectly. I simply do not understand why cmake would care whether or not I actually make an object of a given class!<br>
<br>The following is my CMakeLists.txt file in the highest level directory:<br><br>cmake_minimum_required(VERSION 2.8)<br><br>project(collision CXX)<br><br>add_subdirectory(Extraneous)<br>add_subdirectory(Output)<br>add_subdirectory(Simulation)<br>
add_subdirectory(CollisionObject)<br><br>add_definitions(-ansi -Wall -O2)<br><br>add_executable(collision test.cpp)<br><br>target_link_libraries(collision Simulation)<br>target_link_libraries(collision PriorityQueue)<br>target_link_libraries(collision Event)<br>
target_link_libraries(collision Ball)<br>target_link_libraries(collision SWall)<br>target_link_libraries(collision Circle)<br>target_link_libraries(collision Output)<br>target_link_libraries(collision SimpleMath)<br><br>INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/collision DESTINATION ${CMAKE_SOURCE_DIR})<br>
<br>All of the lower level directories simply had add_library(<libname> <libname.cpp>) in the CMakeLists.txt file. Any help is greatly appreciated!<br><br>Thanks,<br>Matthew<br>