相关文章推荐
细心的羊肉串  ·  在SQL ...·  1 年前    · 
乐观的西瓜  ·  Central Nervous ...·  1 年前    · 
小眼睛的苹果  ·  c# tcpclient send and ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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})
                As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
– Community
                Apr 24 at 17:55
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.