Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
875 views
in Technique[技术] by (71.8m points)

glfw - cmake target_include_directories called with invalid arguments

I am preaty new to cmake . I was using makefiles before but due to QtCreator I am forced to use cmake. I am trying to learn glfw as well too. I have following cmake file:-

cmake_minimum_required(VERSION 3.10)

project(untitled)
find_package(glfw3 3.2 REQUIRED)
find_package(OpenGL REQUIRED)
add_executable(${PROJECT_NAME} "main.cpp")

target_include_directories(untitled ${OPENGL_INCLUDE_DIR})
target_link_libraries(untitled ${OPENGL_gl_LIBRARY})

And I get following error:-

CMakeLists.txt:8: error: target_include_directories called with invalid arguments

I have no Idea what does it mean. Please help me

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you look at the CMake documentation, you'll see that its usage differ a bit from what you wrote:

target_include_directories(<target> [SYSTEM] [BEFORE]
<INTERFACE|PUBLIC|PRIVATE> [items1...] [<INTERFACE|PUBLIC|PRIVATE>
[items2...] ...])

You'll notice that you miss the non optional argument <INTERFACE|PUBLIC|PRIVATE>

You must specify the visibility of the include directory:

target_include_directories(untitled PRIVATE ${OPENGL_INCLUDE_DIR})

If your executable uses OpenGL headers in a public header file, specify it as public so other targets that link to it also includes OpenGL headers.

I suggest you to get used to read the documentation, as it will be your best tool writing CMake scripts.

Even though it's optional, can also take this form for target_link_libraries, which I strongly suggest you do:

target_link_libraries(untitled PUBLIC ${OPENGL_gl_LIBRARY})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...