0

I'm trying to compile a project using hwloc with CMake. However, I get a ton of undefined reference errors when linking:

undefined reference to `hwloc_get_type_depth' undefined reference to `hwloc_bitmap_zero' [...] 

According to this answer to a similar question the order of flags is important.

So, how can I generate a command like this in CMake? :

g++ -Wall -std=c++11 source.cpp-lhwloc

Excerpt from my CMakeLists.txt:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -lhwloc") set(SOURCE_FILES source.cpp) add_executable(source ${SOURCE_FILES}) 

Any help is greatly appreciated!

Edit: My question was proposed as a possible duplicate of this one, however the flag I wanted to add was to link against a library and not a normal compile flag as seems to be the case in the above mentioned question. @Edgar Rokyan provided the right answer for my problem.

2

1 Answer 1

5

If you need to link against hwloc library you might use target_link_libraries command:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") # <== remove *-lhwloc* set(SOURCE_FILES source.cpp) add_executable(source ${SOURCE_FILES}) target_link_libraries(source hwloc) # <== add this line 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! That fixed it. I'll accept your answer as soon as possible.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.