Я довольно новичок в CMake и использую C ++ Frameworks, и у меня возникают проблемы при настройке моего проекта. Когда я пытаюсь построить его, я получаю следующую ошибку
/Users/adjust/Documents/C++/WebService/main.cpp:7:10: fatal error: 'restbed' file not found
Я клонировал репозиторий в свою папку проекта WebService. Сборка не была проблемой, в restbed.build make тест прошел успешно на 100%.
Устранение проблемы не привело к успеху (пока), поэтому я надеюсь, что, возможно, с решением моего ответа другим новичкам, возможно, также помогут в будущем.
Я использую CLion на OS X и мой файл CMakeList.txt следующим образом.
cmake_minimum_required(VERSION 3.7)
project(WebService)
#Set Version
set (WebService_VERSION_MAJOR 1)
set (WebService_VERSION_MAJOR 0)
#Setup Asio
find_path( asio_INCLUDE asio.hpp HINTS "${PROJECT_SOURCE_DIR}/dependency/asio/asio/include" "/usr/include" "/usr/local/include" "/opt/local/include" )
if ( asio_INCLUDE )
set( ASIO_FOUND TRUE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DASIO_STANDALONE=YES" )
message( STATUS "${Green}Found ASIO include at: ${asio_INCLUDE}${Reset}" )
else ( )
message( FATAL_ERROR "${Red}Failed to locate ASIO dependency.${Reset}" )
endif ( )
set(CMAKE_CXX_STANDARD 11)
#Setup OpenSSl
find_library( ssl_LIBRARY ssl ssleay32 HINTS "${PROJECT_SOURCE_DIR}/dependency/openssl/out32dll" "${PROJECT_SOURCE_DIR}/dependency/openssl" "/usr/local/opt/openssl/lib" "/usr/lib" "/usr/local/lib" "/opt/local/lib" )
find_library( crypto_LIBRARY crypto libeay32 HINTS "${PROJECT_SOURCE_DIR}/dependency/openssl/out32dll" "${PROJECT_SOURCE_DIR}/dependency/openssl" "/usr/local/opt/openssl/lib" "/usr/lib" "/usr/local/lib" "/opt/local/lib" )
find_path( ssl_INCLUDE openssl/ssl.h HINTS "${PROJECT_SOURCE_DIR}/dependency/openssl/inc32" "${PROJECT_SOURCE_DIR}/dependency/openssl/include" "/usr/local/opt/openssl/include" "/usr/include" "/usr/local/include" "/opt/local/include" )
if ( ssl_INCLUDE AND ssl_LIBRARY AND crypto_LIBRARY )
set( OPENSSL_FOUND TRUE )
add_definitions( -DBUILD_SSL=TRUE )
if ( APPLE AND BUILD_SSL )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations" )
endif( )
message( STATUS "${Green}Found OpenSSL library at: ${ssl_LIBRARY}${Reset}" )
message( STATUS "${Green}Found OpenSSL include at: ${ssl_INCLUDE}${Reset}" )
message( STATUS "${Green}Found Crypto library at: ${crypto_LIBRARY}${Reset}" )
else ( )
message( FATAL_ERROR "${Red}Failed to locate OpenSSL dependency. see restbed/dependency/openssl; ./config shared; make all${Reset}" )
endif ( )
# RestBED
set( restbed_SOURCE "${PROJECT_SOURCE_DIR}/restbed" )
if ( restbed_SOURCE )
set( restbed_FOUND TRUE )
set( restbed_BUILD "${CMAKE_CURRENT_BINARY_DIR}/restbed_build" )
set( restbed_DISTRIBUTION "${CMAKE_CURRENT_BINARY_DIR}/distribution" )
set( restbed_INCLUDE "${restbed_DISTRIBUTION}/include" )
set( restbed_LIBRARY "${restbed_DISTRIBUTION}/library" )
message( STATUS "${Green}Found Restbed include at: ${restbed_SOURCE}${Reset}" )
else ( )
message( FATAL_ERROR "${Red}Failed to locate Restbed dependency.${Reset}" )
endif ( )
# find all files from restbed library
file(GLOB_RECURSE restbed_LIBRARY_FILES
"${restbed_LIBRARY}/*.a")
include_directories(${restbed_INCLUDE})add_executable(WebService main.cpp)
target_link_libraries(WebService ${restbed_LIBRARY_FILES})
Я понял, что мне нужна только библиотека и включение из папки дистрибутива. Что я делаю неправильно?
Я нашел ошибку, просто убедитесь, что вы устанавливаете путь к фактическому каталогу, вот решение:
cmake_minimum_required(VERSION 3.7)
project(WebService)
#Set Version
set (WebService_VERSION_MAJOR 1)
set (WebService_VERSION_MAJOR 0)
set(CMAKE_CXX_STANDARD 11)
#Setup Asio
find_path( asio_INCLUDE asio.hpp HINTS "${PROJECT_SOURCE_DIR}/dependency/asio/asio/include" "/usr/include" "/usr/local/include" "/opt/local/include" )
if ( asio_INCLUDE )
set( ASIO_FOUND TRUE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DASIO_STANDALONE=YES" )
message( STATUS "${Green}Found ASIO include at: ${asio_INCLUDE}${Reset}" )
else ( )
message( FATAL_ERROR "${Red}Failed to locate ASIO dependency.${Reset}" )
endif ( )
#Setup OpenSSl
find_library( ssl_LIBRARY ssl ssleay32 HINTS "${PROJECT_SOURCE_DIR}/dependency/openssl/out32dll" "${PROJECT_SOURCE_DIR}/dependency/openssl" "/usr/local/opt/openssl/lib" "/usr/lib" "/usr/local/lib" "/opt/local/lib" )
find_library( crypto_LIBRARY crypto libeay32 HINTS "${PROJECT_SOURCE_DIR}/dependency/openssl/out32dll" "${PROJECT_SOURCE_DIR}/dependency/openssl" "/usr/local/opt/openssl/lib" "/usr/lib" "/usr/local/lib" "/opt/local/lib" )
find_path( ssl_INCLUDE openssl/ssl.h HINTS "${PROJECT_SOURCE_DIR}/dependency/openssl/inc32" "${PROJECT_SOURCE_DIR}/dependency/openssl/include" "/usr/local/opt/openssl/include" "/usr/include" "/usr/local/include" "/opt/local/include" )
if ( ssl_INCLUDE AND ssl_LIBRARY AND crypto_LIBRARY )
set( OPENSSL_FOUND TRUE )
add_definitions( -DBUILD_SSL=TRUE )
if ( APPLE AND BUILD_SSL )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations" )
endif( )
message( STATUS "${Green}Found OpenSSL library at: ${ssl_LIBRARY}${Reset}" )
message( STATUS "${Green}Found OpenSSL include at: ${ssl_INCLUDE}${Reset}" )
message( STATUS "${Green}Found Crypto library at: ${crypto_LIBRARY}${Reset}" )
else ( )
message( FATAL_ERROR "${Red}Failed to locate OpenSSL dependency. see restbed/dependency/openssl; ./config shared; make all${Reset}" )
endif ( )
# RestBED
find_path( restbed_SOURCE "${PROJECT_SOURCE_DIR}/restbed" )
if ( restbed_SOURCE )
#set( restbed_FOUND TRUE )
set( restbed_BUILD "${CMAKE_CURRENT_BINARY_DIR}/restbed_build" )
set( restbed_DISTRIBUTION "${restbed_SOURCE}/distribution" )
set( restbed_INCLUDE "${restbed_DISTRIBUTION}/include" )
set( restbed_LIBRARY "${restbed_DISTRIBUTION}/library" )
message( STATUS "${Green}Found Restbed include at: ${restbed_INCLUDE}${Reset}" )
else ( )
message( FATAL_ERROR "${Red}Failed to locate Restbed dependency.${Reset}" )
endif ( )
# find all files from restbed library
file(GLOB_RECURSE restbed_LIBRARY_FILES
"${restbed_LIBRARY}/*.a")
include_directories(${restbed_INCLUDE})#add_executable(WebService ${SOURCE_FILES})
add_executable(WebService main.cpp)
target_link_libraries(WebService ${restbed_LIBRARY_FILES})
Задача ещё не решена.
Других решений пока нет …