You are not logged in.

#1 2014-03-14 14:43:09

pogeymanz
Member
Registered: 2008-03-11
Posts: 1,020

CMake seems to not "see" members defined in header file when building

I'm trying to create a CMake build option for a library that my group is working on. It builds fine with the old-school makefiles that one of my colleagues wrote, so the code isn't the problem- it's my CMake incompetence.

I have a top-level CMakeLists.txt that has an include_subdirectory(library) line.

In the subdirectory, library, I have a CMakeLists.txt that looks like so:

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
set(lib_SOURCES 
    ${CMAKE_CURRENT_SOURCE_DIR}/src/Class1.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/src/Class2.cc
    ${CMAKE_CURRENT_SOURCE_DIR}/src/Class3.cc
    )
add_library(util_lib STATIC ${lib_SOURCES})
install(TARGETS util_lib DESTINATION lib)

With names changed, obviously.

When I run make, it will error on Class2 because it has a Class3 object in the code that accesses a member that is defined in Class3.hh. So it errors with "Class3 has no member named [...]"

So I thought maybe the order of the list mattered. So, I switched the order of Class2 and Class3 in the list, but I still get the same error! Class3 builds fine, but Class2 still errors.

I then tried adding all the .hh files explicitly to the add_library line, which didn't help.

I must be missing something pretty fundamental here.

Offline

#2 2014-03-15 00:20:18

Yggdrasil
Member
Registered: 2009-07-21
Posts: 37

Re: CMake seems to not "see" members defined in header file when building

You mean add_subdirectory in the top level CMakeLists.txt.

You could run:

$ make VERBOSE=1

to see the command used. Compare it to your handwritten Makefile. There's nothing obvious wrong with your cmake script that i can see.

Offline

Board footer

Powered by FluxBB