I am learning CMAKE and the example I have has both link_directories before and after add_executable. My question is: how does the process work? Which is supposed to go first and what is the purpose of one going before the other?
1 Answer
Not sure if this order matter. Probably not. "link_directories" will tell the compiler where to look for the libraries you desire to use. The names of the libraries you put in "target_link_libraries" command.
Actually, with CMake, "link_directories" is not used too often. Usually you use a module script to find your libraries with "find_package" (e.g., findCUDA, findJPEG, etc...) and pass to "target_link_libraries" the variables defined by these scripts containing the full path of each library.
3 Comments
cmakenewbie
What about link_libraries and add_library? Also would there be any point to have link_directories after the final executable is done? That's also on another example code I have but idk if it's written well because it was written by a past intern.
Marco
"after the final executable is done"... Keep in mind CMake is not building any executable or library. It just generates the guy who is gonna do that job. This "guy" can be a gcc Makefile, a Visual Studio project, etc.
cmakenewbie
so the order doesn't matter?