Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c++ - How to link prebuilt libraries with CMake

I have downloaded a library that I have built using the MakeFile provided in the .zip. Now, I am trying to build my own project and link that library using CMake. This is what I have tried so far:

cmake_minimum_required(VERSION 3.10)
project(GraphicsStanfordExample)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_VERBOSE_MAKEFILE ON)

find_library(CPPLIB NAMES libStanfordCPPLib  StanfordCPPLib PATHS ${CMAKE_SOURCE_DIR}/cpplib/lib)

if(NOT CPPLIB)
  message(FATAL_ERROR "cpplib library not found")
endif()

add_executable(graphics_example graphics_example.cpp)

target_link_libraries(graphics_example ${CPPLIB})

The problem here is that it builds and CPPLIB returns True. When I open the project in VS code the header files are found but when I try to compile I get the error: fatal error: gwindow.h: No such file or directory

Clearly I am missing something since the libraries are located by CMake and the IDE but not by the compiler. This is being done in Ubuntu and by generating Unix MakeFiles.

Some help would be appreciated, Thanks!

question from:https://stackoverflow.com/questions/65853420/how-to-link-prebuilt-libraries-with-cmake

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...