I have created a project that uses some boost libraries. Originally the project was created as Eclipse project using MinGW and was working correctly. Now I am trying to convert it into CMake project.
I prepare MinGW makefile with CMake and try to compile it but get the following error:
In file included from D:/Krzych/usr/local/include/boost/date_time/c_time.hpp:17:0,
from D:/Krzych/usr/local/include/boost/date_time/time_clock.hpp:16,
from D:/Krzych/usr/local/include/boost/date_time/posix_time/posix_time_types.hpp:10,
from D:/Krzych/usr/local/include/boost/asio/time_traits.hpp:24,
from D:/Krzych/usr/local/include/boost/asio/deadline_timer_service.hpp:27,
from D:/Krzych/usr/local/include/boost/asio/basic_deadline_timer.hpp:25,
from D:/Krzych/usr/local/include/boost/asio.hpp:22,
from D:/Krzych/Projects/Picard/PicardDebugLink/include/CCommunicationAgent.h:22,
from D:\Krzych\Projects\Picard\PicardDebugLink\source\CCommunicationAgent.cpp:12:
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ctime:65:11: error: '::difftime' has not been declared
using ::difftime;
^
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ctime:66:11: error: '::mktime' has not been declared
using ::mktime;
The same kind of error is repeated for every symbol from time.h referenced in ctime. As you can see ctime is directly included by boost date_time library.
Edit -- CMake files --
main CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (PicardDebugLink)
# The version number.
set (PicardDebugLink_VERSION_MAJOR 0)
set (PicardDebugLink_VERSION_MINOR 9)
if(WIN32)
macro(get_WIN32_WINNT version)
if (WIN32 AND CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REPLACE "." "" ver ${ver})
string(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})
set(${version} "0x${ver}" CACHE PATH "x")
endif()
endmacro()
get_WIN32_WINNT(platform_code)
add_definitions(-D_WIN32_WINNT=${platform_code})
endif()
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/PicardDebugLinkConfig.h.in"
"${PROJECT_BINARY_DIR}/PicardDebugLinkConfig.h"
)
set(CMAKE_CXX_FLAGS "-std=c++11" CACHE STRING "C++2011 features are required" FORCE)
find_package (Boost REQUIRED atomic chrono date_time system timer thread)
include_directories( ${Boost_INCLUDE_DIRS} )
# add the binary tree to the search path for include files
include_directories("${PROJECT_BINARY_DIR}")
include_directories(include)
add_subdirectory(source)
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
message(status "** inc_dirs: ${inc_dirs}")
# build a CPack driven installer package
# include (InstallRequiredSystemLibraries)
set (CPACK_PACKAGE_VERSION_MAJOR "${TreeEight_VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${TreeEight_VERSION_MINOR}")
include (CPack)
File for source subdirectory:
# add the executable
add_library(PicardDebugLink SHARED CCommunicationAgent.cpp
CCommProtocol.cpp
CCreateTest.cpp
CDataStorage.cpp
CException.cpp
CFlashErase.cpp
CFlashFileIOBuff.cpp
CFlashMemIOBuff.cpp
CFlashWriteFile.cpp
CFlashWriteMem.cpp
CFrameCreator.cpp
CIOBuff.cpp
CSerialLink.cpp
ErrorCategories.cpp
FlashProtocols.cpp
IThrowable.cpp
ProgramFPGADataHelpers.cpp
ProgramFPGAProtocols.cpp
SPicardCommunicationFrame.cpp
utilities.cpp
)
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
target_link_libraries(PicardDebugLink ${Boost_LIBRARIES} )
# add the install targets
install (TARGETS PicardDebugLink DESTINATION bin)
install (FILES "include/*.h" DESTINATION include)
Related
I am trying to make node.js native addon which use cmake to compile c++ code...
CMakeLists.txt file
cmake_minimum_required(VERSION 3.15)
# Name of the project (will be the name of the plugin)
project (addon)
set(CMAKE_CXX_STANDARD 11)
# Don't add this line if you will try_compile with boost.
# set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME ON)
find_package(Boost)
# Essential include files to build a node addon,
# you should add this line in every CMake.js based project.
include_directories(${CMAKE_JS_INC} ${Boost_INCLUDE_DIRS})
# Declare the location of the source files
file(GLOB SOURCE_FILES "src/*.cpp" "src/*.h")
# This line will tell CMake that we're building a shared library
# from the above source files
# named after the project's name
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
# This line will give our library file a .node extension without any "lib" prefix
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
# Essential library files to link to a node addon,
# you should add this line in every CMake.js based project.
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} ${Boost_LIBRARIES})
# Include N-API wrappers
execute_process(COMMAND node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR
)
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})
add_definitions(-DNAPI_VERSION=3)
I am using websocketpp library which is internally dependent on boost
And while compiling I am getting this error:
LINK : fatal error LNK1104: cannot open file 'libboost_random-vc142-mt-x64-1_74.lib' [C:\Users\atiqg\Desktop\Tom\muteme\shells\electron\na
tive_module\build\addon.vcxproj]
libboost_random-vc142-mt-x64-1_74.lib is present in boost_1_71_0/stage/x64/lib folder
And this path is added in environments variables too....
I'm currently working on a school project with Visual Studio 2019, and we face a problem:
LINK : fatal error LNK1104: cannot open file 'Irrlicht.lib'
The error only came when we already have compiled our CMake file, the first time it's working.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.9)
project(IndieCMAKE)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
find_package(Irrlicht)
link_libraries(Irrlicht)
INCLUDE_DIRECTORIES(
"/usr/include/irrlicht"
"./include"
${PROJECT_SOURCE_DIR}/include
)
include_directories(inc)
add_executable(IndieCMAKE
./main.cpp)
Here is my FindIrrlicht.cmake file:
IF (NOT Irrlicht_INCLUDE_DIRS OR NOT Irrlicht_LIBRARIES)
FIND_PATH(Irrlicht_INCLUDE_DIRS
NAMES
irrlicht.h
PATHS
/usr/include/irrlicht/ # Default Fedora28 system include path
/usr/local/include/irrlicht/ # Default Fedora28 local include path
${CMAKE_MODULE_PATH}/include/ # Expected to contain the path to this file for Windows10
${Irrlicht_DIR}/include/ # Irrlicht root directory (if provided)
)
IF (MSVC) # Windows
SET(CMAKE_FIND_LIBRARY_PREFIXES "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
ELSE (MSVC) # Linux
SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
ENDIF(MSVC)
FIND_LIBRARY(Irrlicht_LIBRARIES
NAMES
Irrlicht
PATHS
/usr/lib64 # Default Fedora28 library path
/usr/lib/ # Some more Linux library path
/usr/lib/x86_64-linux-gnu/ # Some more Linux library path
/usr/local/lib/ # Some more Linux library path
/usr/local/lib64/ # Some more Linux library path
${CMAKE_MODULE_PATH}/ # Expected to contain the path to this file for Windows10
${Irrlicht_DIR}/ # Irrlicht root directory (if provided)
)
ENDIF (NOT Irrlicht_INCLUDE_DIRS OR NOT Irrlicht_LIBRARIES)
IF (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
SET(Irrlicht_FOUND TRUE)
ELSE (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
SET(Irrlicht_FOUND FALSE)
ENDIF (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
IF (Irrlicht_FIND_REQUIRED AND NOT Irrlicht_FOUND)
MESSAGE(FATAL_ERROR
" Irrlicht not found.\n"
" Windows: Fill CMake variable CMAKE_MODULE_PATH to the provided directory.\n"
" Linux: Install Irrlicht using your package manager ($> sudo dnf install irrlicht-devel).\n"
)
ENDIF (Irrlicht_FIND_REQUIRED AND NOT Irrlicht_FOUND)
Here are my CMake GUI variables:
If you are using a CMake Find Module, such as a FindIrrlicht.cmake file, the find_package(Irrlicht) command should populate some Irrlicht_* CMake variables for you. Assuming find_package() actually found the package components correctly, you can use these Irrlicht_* variables in your CMake file to specify where CMake should look for Irrlicht package headers and libraries.
Something like the following CMake file should work:
cmake_minimum_required(VERSION 3.9)
project(IndieCMAKE)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# Use REQUIRED here, to ensure CMake finds the package before continuing.
find_package(Irrlicht REQUIRED)
# Don't use this command. It's old, and the syntax didn't work, in your case.
#link_libraries(Irrlicht)
# Specify your directories that contain headers, including the Irrlicht headers.
include_directories(
${Irrlicht_INCLUDE_DIRS}
)
# Define your executable target.
add_executable(IndieCMAKE
main.cpp
)
# Link the Irrlicht library to your executable target.
target_link_libraries(IndieCMAKE PRIVATE ${Irrlicht_LIBRARIES})
So I'm using CMake to build a C++ project (on Mac OS) and my project relies on a dylib (I'm using TBB https://www.threadingbuildingblocks.org/ but the specific library itself doesn't matter)
If I do a standard "cmake" and "make" it builds the executable where I want it and when I run my app, the dylib links correctly and everything works perfectly.
The problem comes in when I try to do a "make install" and try to run the resulting executable from the install directory. I get an "image not found" error:
dyld: Library not loaded: #rpath/libtbb.dylib
Referenced from:
/Users/MyName/Desktop/ProjectRoot/install/./MyApp
Reason: image not found
Interestingly, if I do a regular "make" without an install, and then manually copy over the executable to the install directory, then that will link against my dylib properly. I have no idea why that is.
My directory structure is as follows:
Root
CMakeLists.txt
Source/
Libraries/
tbb/
include/
lib/
libtbb.dylib
install/
...and my CMakeLists.txt file is below:
# Start of CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project (MyApp)
# Set C++ version and output paths
set (CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# Find TBB
find_library (
TBB_LIBRARIES
NAMES tbb libtbb # what to look for
HINTS "${CMAKE_SOURCE_DIR}/Libraries/tbb/lib" # where to look
NO_DEFAULT_PATH # do not search system default paths
)
# Set Custom Include Files + TBB header files
include_directories(Source/Headers Libraries/tbb/include)
# Set Source Files
file(GLOB_RECURSE SRC_FILES "Source/*.cpp")
add_executable(MyApp ${SRC_FILES})
# Link Libraries
target_link_libraries(MyApp ${TBB_LIBRARIES})
# Set compile flags
set_target_properties(MyApp PROPERTIES CXX_STANDARD 14) #LINK_FLAGS "-Wl")
target_compile_features(MyApp PUBLIC cxx_std_14)
# Install executable
install(TARGETS MyApp DESTINATION .)
If I try to also add the following line, and install the dylib as well:
install(TARGETS ${TBB_LIBRARIES} DESTINATION lib)
then when I do a "make install" I get the following error instead:
install TARGETS given target
"/Users/MyName/Desktop/ProjectRoot/Libraries/tbb/lib/libtbb.dylib"
which does not exist in this directory.
So I just can't seem to get this install to work. How do I fix it so that both my executable and my library get installed in the right place and that my executable will be able to link against my library when run?
I'm creating a native library under Android Studio, and I'm hurting the following problem.
In my AndroidStudio project CMakeLists.txt, I have this:
cmake_minimum_required(VERSION 3.7.0)
add_library(native-lib
SHARED
src/main/cpp/native-lib.cpp )
IF(USE_EXTERNAL)
include(ExternalProject)
ExternalProject_Add(
project_mylib
DOWNLOAD_COMMAND ""
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/mylib/"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}
)
add_dependencies(native-lib project_mylib)
ELSE()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/mylib/)
ENDIF()
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries(native-lib
${log-lib}
mylib
)
A self-made library is located in src/main/cpp/mylib/, with a CMakeLists.txt:
cmake_minimum_required(VERSION 3.7.0)
project(lib)
add_library(mylib SHARED lib.cpp)
INSTALL(TARGETS mylib
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
)
When I use the "traditional" add_subdirectory(...) everything goes well. But, if I use the ExternalProject_Add(...) version, linker is skipping the compiled libmylib.so library and so cannot link mylib to native-lib.
I have the following message: skipping incompatible /home/.../app/.externalNativeBuild/cmake/debug/arm64-v8a/lib/libmylib.so when searching for -lmylib
My guess is that all the flags set by AndroidStudio for the root CMakeLists.txt are not set when the ExternalProject is compile leading to an incompatible shared library.
So, I wonder if there is a way to compile a cmake ExternalProject like it was part of the root project (sharing the same compile flags etc) ?
Thanks for any advice
I have cli wrapper function which i am trying to configure in cmake. After i generate the project with cmake the generated .proj file does not have the property of clr support is set to no common languaage runtime support. below is my cmake file
# This is the root ITK CMakeLists file.
cmake_minimum_required(VERSION 2.8.9)
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0003 NEW)
endif()
set_target_properties(${TargetName} PROPERTIES COMPILE_FLAGS "/clr")
SET(LINK_LIBRARIES
D:\\2016\\RandomSlicing\\Processing\\lib\\obliquePlane.lib
)
# The header files
SET(HEADERS
ObliquePlaneWrapper.h
obliquePlane.h
)
# The implementation files
SET(SOURCES
ObliquePlaneWrapper.cpp
)
# Find ITK.
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
# Add this as include directory
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}
${SOURCE_PATH}
${VXL_INCLUDE_DIRS}
)
# Main library
#ADD_EXECUTABLE(obliquePlane ${HEADERS} ${SOURCES})
ADD_LIBRARY(ObliquePlaneWrapper SHARED ${HEADERS} ${SOURCES})
TARGET_LINK_LIBRARIES(ObliquePlaneWrapper ${LINK_LIBRARIES} ${ITK_LIBRARIES})
I manually set this property in the All_build project and the corresponding .proj file. When i build the project it is searching for the ObliquePlaneWrapper.dll which it should be generating. Is this a problem because of some flag not set for common language runtime support
You can manually supply Compile Flags to specific sources to be compiled with specific flags. This includes \CLR for Visual C++. See example here.
https://cmake.org/pipermail/cmake/2011-April/043773.html