On 24.10.08 00:22:25, Stefán Freyr Stefánsson wrote:
> ADD_EXECUTABLE( app src/app.cpp )
> 
> When app.cpp is compiled I get an error complaining that there is an 
> "undefined reference to Config::Config()".
> 
> So (finally) my question is: Since common has no executables, how exactly 
> should I tell CMake that it needs to compile Config.cpp before moduleA 
> compiles its executable for app.cpp to get rid of this error?

You either need to create a library for the common project or you need to
add Config.cpp do "app", i.e. instead of the above add_executable this one:

add_executable( app src/app.cpp
                    ${COMMON_SOURCE_DIR}/src/Config.cpp )
 
> Do I need to add something to the common CMakeLists.txt file (which would be 
> the cleanest solution IMHO), and then what exactly is it that I need to add, 
> or should I somehow indicate that this file needs to be compiled in the 
> moduleA CMakeLists.txt (which feels a bit wrong since the idea about the 
> common project is to be referenced by more than one module). I guess I could 
> use ADD_LIBRARY like in the example, but is that the right thing to do? I 
> mean, basically I just want to reference the files from my modules, it's not 
> exactly a library, just some common files. Maybe this is my mistake?

Well, what you actually want is the code from common to be available inside
"app". This means the code either has to be compiled into app like shown
above. Or app has to link against a library that provides the code. If you
don't want to compile Config.cpp as often as you have moduleX, then I
suggest to create a static library inside common that each app links
against. This means no runtime-dependency on that library, but your
moduleX's can share the code without each compiling it.

Andreas

-- 
Good day for a change of scene.  Repaper the bedroom wall.
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to