The Problem
I'm working with CentOS 7 and have been trying to correct an issue with the build instructions, especially when trying to locate the glfw library. Following the instructions from the HOWTOBUILD.txt file (available from the SB7 git repo) I regularly received an error when running the make command:
[sweet_ass_user_name#bitchin_camaro build]$ make
Scanning dependencies of target sb7
[ 1%] Building CXX object CMakeFiles/sb7.dir/src/sb7/sb7.cpp.o
[ 1%] Building CXX object CMakeFiles/sb7.dir/src/sb7/sb7color.cpp.o
[ 2%] Building CXX object CMakeFiles/sb7.dir/src/sb7/sb7ktx.cpp.o
[ 2%] Building CXX object CMakeFiles/sb7.dir/src/sb7/sb7object.cpp.o
/usr/local/opengl/SDK_Sandbox/sb7code/src/sb7/sb7object.cpp: In member function ‘void sb7::object::render_sub_object(unsigned int, unsigned int, unsigned int)’:
/usr/local/opengl/SDK_Sandbox/sb7code/src/sb7/sb7object.cpp:212:77: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
(void*)sub_object[object_index].first,
^
[ 3%] Building CXX object CMakeFiles/sb7.dir/src/sb7/sb7shader.cpp.o
[ 4%] Building CXX object CMakeFiles/sb7.dir/src/sb7/sb7textoverlay.cpp.o
[ 4%] Building C object CMakeFiles/sb7.dir/src/sb7/gl3w.c.o
[ 5%] Linking CXX static library lib/libsb7.a
[ 5%] Built target sb7
Scanning dependencies of target wrapmodes
[ 6%] Building CXX object CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o
[ 7%] Linking CXX executable ../bin/wrapmodes
/usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status
make[2]: *** [../bin/wrapmodes] Error 1
make[1]: *** [CMakeFiles/wrapmodes.dir/all] Error 2
make: *** [all] Error 2
To make things more confusing, I had already installed these packages:
glfw
glfw-devel
When checking my installed glfw packages, with rpm -qa | grep glfw, my system returns:
glfw-3.2.1-2.el7.x86_64
glfw-devel-3.2.1-2.el7.x86_64
So clearly, the installed glfw library is version 3 of the glfw library.
Yet, why won't the system recognize it?
The Background and System Information
OS: centos-release-7-5.1804.4.el7.centos.x86_64
OpenGL: 4.6.0 NVIDIA 396.37
GPU: GV100
Optix: 5.1
CUDA: 9.2
CMake: cmake3, cmake3-gui
OpenGL libraries:
mesa-libGLU-9.0.0-4.el7.x86_64
mesa-libGLES-17.2.3-8.20171019.el7.x86_64
mesa-libGLU-devel-9.0.0-4.el7.x86_64
mesa-libwayland-egl-17.2.3-8.20171019.el7.x86_64
mesa-libGL-17.2.3-8.20171019.el7.x86_64
mesa-filesystem-17.2.3-8.20171019.el7.x86_64
mesa-libEGL-17.2.3-8.20171019.el7.x86_64
mesa-dri-drivers-17.2.3-8.20171019.el7.x86_64
mesa-libglapi-17.2.3-8.20171019.el7.x86_64
mesa-libxatracker-17.2.3-8.20171019.el7.x86_64
mesa-libGL-devel-17.2.3-8.20171019.el7.x86_64
mesa-libgbm-17.2.3-8.20171019.el7.x86_64
Graphics Misc Libs:
libX11-common-1.6.5-1.el7.noarch
libX11-1.6.5-1.el7.x86_64
libX11-devel-1.6.5-1.el7.x86_64
libXinerama-1.1.3-2.1.el7.x86_64
libXinerama-devel-1.1.3-2.1.el7.x86_64
glfw-3.2.1-2.el7.x86_64
glfw-devel-3.2.1-2.el7.x86_64
Links
OpenGL SuperBible v7 Code Repo
SB7 HOWTOBUILD.txt
The Answer
Turns out, because of a confusing naming issue regarding the difference between the glfw package and the glfw version, the answer was simply to modify the CMakeLists.txt file (link here: SB7 CMakeLists.txt)
Line 28 needed a single character removed. Change glfw3 to glfw.
BUT!!
Do not also be rename the glfw3 name from the line above. I can only assume that this is referring to the version of glfw3, and not the name of the package.
Now, the code builds and all the builds run fine.
Additional Notes
For the centos7 system, and in order to work with current build rules for CUDA, you'll need to run cmake3 .. (instead of cmake)
Fixed Code
cmake_minimum_required (VERSION 2.6)
project (superbible7)
LINK_DIRECTORIES( ${CMAKE_SOURCE_DIR}/lib )
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
# Second, for multi-config builds (e.g. msvc)
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/lib )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_SOURCE_DIR}/lib )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
find_package(OpenGL)
set (CMAKE_DEBUG_POSTFIX "_d")
if(WIN32)
set(COMMON_LIBS sb7 optimized glfw3 debug glfw3_d ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES})
elseif (UNIX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLFW REQUIRED glfw3)
set(COMMON_LIBS sb7 glfw X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL rt dl)
else()
set(COMMON_LIBS sb7)
endif()
Related
I am trying to install a custom library with CMake.
It consists of 2 'sub-libraries' and a main header file which includes the 'sub-libraries'.
I think it installs okay (The output looks like this:)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/Desktop/Projects/MaxLib/build
[ 20%] Building CXX object Geom/CMakeFiles/Geom.dir/Geom.cpp.o
[ 40%] Linking CXX shared library libGeom.so
[ 40%] Built target Geom
[ 60%] Building CXX object File/CMakeFiles/File.dir/File.cpp.o
[ 80%] Linking CXX shared library libFile.so
[ 80%] Built target File
[100%] Built target MaxLib
Install the project...
-- Install configuration: "Debug"
-- Installing: /usr/local/lib/libMaxLib.a
-- Installing: /usr/local/include/MaxLib.h
-- Installing: /usr/local/include/MaxLib/File.h
-- Installing: /usr/local/include/MaxLib/Geom.h
However, when I try to compile a program using it, I receive a number of "undefined reference to" errors. Where have I gone wrong?
The Main Header looks like:
#include "MaxLib/File.h"
#include "MaxLib/Geom.h"
It's CMakefile looks like this:
cmake_minimum_required(VERSION 3.5)
project(MaxLib)
add_library(${PROJECT_NAME}
"${CMAKE_CURRENT_SOURCE_DIR}/MaxLib.h"
)
add_subdirectory(File)
add_subdirectory(Geom)
target_link_libraries(${PROJECT_NAME} File)
target_link_libraries(${PROJECT_NAME} Geom)
# Install Library
install (TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib)
# Install Main Header File
INSTALL(FILES "${CMAKE_CURRENT_SOURCE_DIR}/MaxLib.h" DESTINATION include) #
INSTALL(FILES ...) or install(DIRECTORY ...)
# Build list of header files to install from other directorys. Root == "."
set(HEADER_DIRS "File" "Geom")
## Add Source Files from the other directories
foreach(DIR ${HEADER_DIRS})
# Find all source files & append to list
if(DIR STREQUAL ".")
file(GLOB HEADER_FILES_IN_FOLDER *.h)
else()
file(GLOB HEADER_FILES_IN_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${DIR}/*.h)
endif()
list(APPEND HEADER_FILES ${HEADER_FILES_IN_FOLDER})
endforeach()
# Install Header files
INSTALL(FILES ${HEADER_FILES} DESTINATION include/${PROJECT_NAME}) # INSTALL(FILES ...) or install(DIRECTORY ...)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -g)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
The 'sub-libraries's CMakefiles look like this:
project(Geom)
add_library(${PROJECT_NAME} SHARED
${CMAKE_CURRENT_SOURCE_DIR}/Geom.cpp
)
target_include_directories(${PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
I am trying to include the library like this:
#include <MaxLib.h>
And I am adding -lMaxLib to its makefile
Edit:
A basic program like this:
#include <MaxLib.h>
int main() {
float y1 = MaxLib::Geom::CleanAngle(7654);
}
Will produce the undefined reference error:
/usr/bin/ld: warning: libFile.so, needed by //usr/local/lib/libMaxLib.so, not found (try using -rpath or -rpath-link) // This shows when add_library marked SHARED
/usr/bin/ld: warning: libGeom.so, needed by //usr/local/lib/libMaxLib.so, not found (try using -rpath or -rpath-link) // This shows when add_library marked SHARED
/home/pi/Desktop/Projects/TestProgram/main.cpp:43: undefined reference to `MaxLib::Geom::CleanAngle(double)'
This is less about C++, and more about specific compiling avcodec and avformat as those are used inside FFmpeg. I'm trying to compile for the first time ffmpeg project code. All the linking has been resolved, and the program errors our.
I'm writing my first program - attempt at avformat libraries inside my C++ code. Linker errors on this line:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/sasha/CLionProjects/ffmpeg-01 --target all -- -j 12
Scanning dependencies of target docs
[ 5%] Generating HTML documentation
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/input.c.o
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/init.c.o
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/context.c.o
[ 30%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/vulkan.c.o
[ 30%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/monitor.c.o
[ 35%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_init.m.o
[ 45%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_joystick.m.o
[ 45%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/window.c.o
[ 50%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_monitor.m.o
[ 60%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_window.m.o
[ 60%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_time.c.o
[ 60%] Built target docs
[ 65%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/posix_thread.c.o
[ 70%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/nsgl_context.m.o
[ 75%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/egl_context.c.o
[ 80%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/osmesa_context.c.o
[ 85%] Linking C static library libglfw3.a
[ 85%] Built target glfw
[ 95%] Building CXX object CMakeFiles/ffmpeg_01.dir/src/main.cpp.o
[ 95%] Building CXX object CMakeFiles/ffmpeg_01.dir/src/load_frame.cpp.o
[100%] Linking CXX executable ffmpeg_01
clang: error: no such file or directory: 'VideoToolbox'
clang: error: no such file or directory: 'CoreFoundation'
clang: error: no such file or directory: 'CoreMedia'
clang: error: no such file or directory: 'CoreVideo'
clang: error: no such file or directory: 'CoreServices'
clang: error: no such file or directory: 'OpenGL'
clang: error: no such file or directory: 'CoreImage'
clang: error: no such file or directory: 'AppKit'
clang: error: no such file or directory: 'Foundation'
clang: error: no such file or directory: 'CoreAudio'
clang: error: no such file or directory: 'AVFoundation'
clang: error: no such file or directory: 'CoreGraphics'
make[2]: *** [ffmpeg_01] Error 1
make[1]: *** [CMakeFiles/ffmpeg_01.dir/all] Error 2
make: *** [all] Error 2
This is the content of my *libavcodec.pc file, and it has an entry of conflicts: which lists all of the items that clang cannot find, I don't know if those are linked somehow. I found a source pointing that similar error appears if I had other forks of ffmpeg, but I do not.
prefix=/usr/local
exec_prefix=${prefix}
libdir=/usr/local/lib
includedir=/usr/local/include
Name: libavcodec
Description: FFmpeg codec library
Version: 58.108.100
Requires: libswresample >= 3.8.100, libavutil >= 56.60.100
Requires.private:
Conflicts:
Libs: -L${libdir} -lavcodec -liconv -lm -llzma -lz -framework AudioToolbox -L/usr/local/Cellar/x264/r3011/lib -lx264 -pthread -framework VideoToolbox -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices
Libs.private:
Cflags: -I${includedir}
I don't have experience in cmakefile, I can paste it here if needed.
Any help is greatly appreciated, because I'm stuck for the past several days.
I have two CMakeLists:
cmake_minimum_required(VERSION 3.17)
project(ffmpeg_01)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(lib/glfw)
add_subdirectory(lib/FFmpeg)
add_definitions(-DGL_SILENCE_DEPRECIATION)
if(APPLE)
list(APPEND EXTRA_LIBS
"-framework OpenGL"
)
elseif(LINUX)
list(APPEND EXTRA_LIBS
"-lGL -lGLU -lX11")
endif()
add_executable(ffmpeg_01 src/main.cpp src/load_frame.cpp)
target_link_libraries(ffmpeg_01 FFmpeg glfw ${EXTRA_LIBS})
and the interface for FFmpeg under FFmpeg sub directory:
cmake_minimum_required(VERSION 3.17)
project(FFMPEG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(AVCODEC REQUIRED IMPORTED_TARGET libavcodec)
pkg_check_modules(AVFORMAT REQUIRED IMPORTED_TARGET libavformat)
pkg_check_modules(AVFILTER REQUIRED IMPORTED_TARGET libavfilter)
pkg_check_modules(AVDEVICE REQUIRED IMPORTED_TARGET libavdevice)
pkg_check_modules(AVUTIL REQUIRED IMPORTED_TARGET libavutil)
pkg_check_modules(SWRESAMPLE REQUIRED IMPORTED_TARGET libswresample)
pkg_check_modules(SWSCALE REQUIRED IMPORTED_TARGET libswscale)
add_library(FFmpeg INTERFACE IMPORTED GLOBAL)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVCODEC)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVFORMAT)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVFILTER)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVDEVICE)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVUTIL)
target_link_libraries(FFmpeg INTERFACE PkgConfig::SWRESAMPLE)
target_link_libraries(FFmpeg INTERFACE PkgConfig::SWSCALE)
I also tried adding the following block below target_link_libraries, but no difference on compilation outcome:
target_link_options(FFmpeg INTERFACE
${AVCODEC_LDFLAGS_OTHERS}
${AVFORMAT_LDFLAGS_OTHERS}
${AVFILTER_LDFLAGS_OTHERS}
${AVDEVICE_LDFLAGS_OTHERS}
${AVUTIL_LDFLAGS_OTHERS}
${SWRESAMPLE_LDFLAGS_OTHERS}
${SWSCALE_LDFLAGS_OTHERS}
)
I am using the experimental GLM hash features in a CMake project.
Everything works fine unless the project is generated by Clion.
When building the Clion generated project GLM raises the error "GLM_GTX_hash requires C++11 standard library support" (see CMake logs) although C++11 is enabled.
Building the same, clion generated, project from a terminal fails with the same error.
However, when generating and building the project with cmake 'manually' (without Clion even knowing about it) everything works fine. As expected.
GLM is not directly included in the CMakeList. GLFW includes/imports it.
Example CMakeLists.txt
(...)
set(CMAKE_CXX_STANDARD 11)
add_executable(Test main.cpp)
(...)
add_subdirectory("glfw" ${CMAKE_CURRENT_BINARY_DIR}/glfw)
target_include_directories(Test PUBLIC ${GLFW_INCLUDE_DIRS})
target_link_libraries(Test ${GLFW_LIBRARIES} glfw)
Example main.cpp
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/hash.hpp>
int main() {
return 0;
}
Clion build output:
/usr/bin/cmake --build /home/lukas/Test/cmake-build-debug --target Test -- -j 2
[ 89%] Built target glfw
Scanning dependencies of target Test
[ 94%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
In file included from /home/lukas/Test/main.cpp:8:
/usr/include/glm/gtx/hash.hpp:46:3: error: "GLM_GTX_hash requires C++11 standard library support"
# error "GLM_GTX_hash requires C++11 standard library support"
^
1 error generated.
make[3]: *** [CMakeFiles/Test.dir/build.make:63: CMakeFiles/Test.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/Test.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/Test.dir/rule] Error 2
make: *** [Makefile:118: Test] Error 2
Terminal output (as expected)
$ cmake -H. -Bbuild -G "Unix Makefiles" && cmake --build build
Scanning dependencies of target glfw
[ 5%] Building C object glfw/src/CMakeFiles/glfw.dir/context.c.o
[ 10%] Building C object glfw/src/CMakeFiles/glfw.dir/init.c.o
[ 15%] Building C object glfw/src/CMakeFiles/glfw.dir/input.c.o
[ 21%] Building C object glfw/src/CMakeFiles/glfw.dir/monitor.c.o
[ 26%] Building C object glfw/src/CMakeFiles/glfw.dir/vulkan.c.o
[ 31%] Building C object glfw/src/CMakeFiles/glfw.dir/window.c.o
[ 36%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_init.c.o
[ 42%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_monitor.c.o
[ 47%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_window.c.o
[ 52%] Building C object glfw/src/CMakeFiles/glfw.dir/xkb_unicode.c.o
[ 57%] Building C object glfw/src/CMakeFiles/glfw.dir/posix_time.c.o
[ 63%] Building C object glfw/src/CMakeFiles/glfw.dir/posix_thread.c.o
[ 68%] Building C object glfw/src/CMakeFiles/glfw.dir/glx_context.c.o
[ 73%] Building C object glfw/src/CMakeFiles/glfw.dir/egl_context.c.o
[ 78%] Building C object glfw/src/CMakeFiles/glfw.dir/osmesa_context.c.o
[ 84%] Building C object glfw/src/CMakeFiles/glfw.dir/linux_joystick.c.o
[ 89%] Linking C static library libglfw3.a
[ 89%] Built target glfw
Scanning dependencies of target Test
[ 94%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
[100%] Linking CXX executable Test
[100%] Built target Test
Now I am actually curious about rather I messed up somewhere or if it is simply a bug. And if so, where should I report it?
[Clion/Jetbrains?, GLM?, GLFW?, CMake?]
Thanks in advance
Update
I am using the latest available (for me) builds:
CMake version: 3.14.4
Operating System: Arch Linux 5.0.18-1 x86_64 GNU/Linux
GLFW version/commit: d834f01c
GLM version/commit: fce2abd0
Clion: 2019.1.3
Clion EAP: 2019.2 EAP
Final update / 'Solution'
I just discovered that the problem is Clang, not Clion or anything else.
Clion simply defaulted to Clang (instead of GCC).
There are bug reports for GLM and Clang already existing (with potential fixes!):
https://github.com/g-truc/glm/issues/620
https://github.com/g-truc/glm/issues/646
Thank you very much everyone ~
I've been writing a compiler using LLVM as the backend. The CMake files I've written so far have worked on Linux, but I haven't had any luck on Windows. The project is split into a library and "driver" executable with their own CMakeLists.txt in separate subdirectories.
The top level CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 3.7.0)
project (compiler)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
find_package (LLVM REQUIRED CONFIG)
message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message (STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories (${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_subdirectory (Compiler_Lib)
add_subdirectory (Compiler_exe)
The CMakeLists.txt for the library:
cmake_minimum_required (VERSION 3.7.0)
add_library (compiler_lib
AST.cpp
AST.h
parser.cpp
parser.h
scanner.cpp
scanner.h
token.cpp
token.h
visualizer.cpp
visualizer.h
codegen.cpp
codegen.h)
target_include_directories (compiler_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(compiler_lib LLVM)
And the CMakeLists.txt for the executable (which is where linking to the libraries fails):
cmake_minimum_required (VERSION 3.7.0)
project (compiler_exe)
add_executable (compiler_exe Compiler_exe.cpp getopt.h getopt.cpp)
target_link_libraries (compiler_exe LINK_PUBLIC LLVM compiler_lib)
I run the command "c:\Program Files\CMake\bin\cmake.exe" .. -G"MinGW Makefiles" -DCMAKE_PREFIX_PATH=C:\Users\James\llvm+clang-7.0.0-win64-msvc-release where C:\Users\James\llvm+clang-7.0.0-win64-msvc-release is the path to prebuilt LLVM libraries. However, running mingw32-make afterwards fails with the output
Scanning dependencies of target compiler_lib
[ 10%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/AST.cpp.obj
[ 20%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/parser.cpp.obj
[ 30%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/scanner.cpp.obj
[ 40%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/token.cpp.obj
[ 50%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/visualizer.cpp.obj
[ 60%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/codegen.cpp.obj
[ 70%] Linking CXX static library libcompiler_lib.a
[ 70%] Built target compiler_lib
Scanning dependencies of target compiler_exe
[ 80%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/Compiler_exe.cpp.obj
[ 90%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/getopt.cpp.obj
[100%] Linking CXX executable compiler_exe.exe
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lLLVM
collect2.exe: error: ld returned 1 exit status
Compiler_exe\CMakeFiles\compiler_exe.dir\build.make:102: recipe for target 'Compiler_exe/compiler_exe.exe' failed
mingw32-make[2]: *** [Compiler_exe/compiler_exe.exe] Error 1
CMakeFiles\Makefile2:176: recipe for target 'Compiler_exe/CMakeFiles/compiler_exe.dir/all' failed
mingw32-make[1]: *** [Compiler_exe/CMakeFiles/compiler_exe.dir/all] Error 2
Makefile:82: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
This is the first time I've used CMake so I could have missed something obvious, but as I say it seems to work on Linux.
For the linking to succeed two things need to be true:
1) the file libLLVM.a needs to exist
2) that file has to be in a directory in the library search path
There should be a way to get cmake to tell you the list of places it searches for libraries, and you need to find a way to get wherever libLLVM.a exists into that list of dirs.
Apologies for the partial answer, but that's the troubleshooting path...
I am trying to use / learn CMake to embed Python into a C++ application that uses Qt.
I am using FIND_PACKAGE in an attempt to get a non-system package installation (Anaconda Python 2.7.9) in. I can not get the compiler to see any version other than the system installation (version 2.7.5).
My CMakeLists.txt is:
#Minimum CMAKE version
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
#Name the project
PROJECT(embedpython)
#Set the version number
SET(embedpython_VERSION_MAJOR 0)
SET(embedpython_VERSION_MINOR 1)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
FIND_PACKAGE(Qt4 4.8.6 REQUIRED QtGui QtCore)
QT4_WRAP_CPP(embedpython_HEADERS_MOC ${embedpython_HEADERS})
message(status "QT FOUND: ${Qt4_FOUND}")
FIND_PACKAGE(PythonLibs 2.7.9 REQUIRED)
message(status "libs found: ${PYTHONLIBS_FOUND}")
MESSAGE(STATUS "PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}")
MESSAGE(STATUS "PYTHON_INCLUDE_PATH: ${PYTHON_INCLUDE_PATH}")
MESSAGE(STATUS "PYTHONLIBS_VERSION: ${PYTHONLIBS_VERSION_STRING}")
MESSAGE(STATUS "PYTHON_INCLUDE_DIRS: ${PYTHON_INCLUDE_DIRS}")
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
SET(embedpython_SOURCES
main.cpp
mainwindow.cpp
pythonutilsimpl.cpp
ipcepythonrunner.cpp)
SET(embedpython_HEADERS
mainwindow.h
pythonutilsimpl.h
ipcepythonutils.h
ipcepythonrunner.h)
ADD_EXECUTABLE(embedpython ${embedpython_SOURCES} ${embedpython_HEADERS_MOC})
TARGET_LINK_LIBRARIES(embedpython ${QT_LIBRARIES} ${PYTHON_LIBRARIES})
Which outputs:
cmpt:build user$ /Applications/CMake.app/Contents/bin/cmake .. && make
statusQT FOUND: TRUE
statuslibs found: TRUE
-- PYTHON_LIBRARIES: /home/me/anaconda/lib/libpython2.7.dylib
-- PYTHON_INCLUDE_PATH: /home/me/anaconda/include/python2.7
-- PYTHONLIBS_VERSION: 2.7.9
-- PYTHON_INCLUDE_DIRS: /home/me/anaconda/include/python2.7
-- Configuring done
-- Generating done
-- Build files have been written to: /home/me/Desktop/EmbedPython/build
Scanning dependencies of target embedpython_automoc
[ 16%] Automatic moc for target embedpython
Generating moc_mainwindow.cpp
[ 16%] Built target embedpython_automoc
Scanning dependencies of target embedpython
[ 33%] Building CXX object CMakeFiles/embedpython.dir/main.cpp.o
[ 50%] Building CXX object CMakeFiles/embedpython.dir/mainwindow.cpp.o
[ 66%] Building CXX object CMakeFiles/embedpython.dir/pythonutilsimpl.cpp.o
[ 83%] Building CXX object CMakeFiles/embedpython.dir/ipcepythonrunner.cpp.o
[100%] Building CXX object CMakeFiles/embedpython.dir/embedpython_automoc.cpp.o
Linking CXX executable embedpython
[100%] Built target embed python
Using ccmake, I have set PYTHON_INCLUDE_DIR and PYTHON_LIBRARY so that FIND_PACKAGE succeeds in finding Python 2.7.9.
Within the C++ I have a debug to print the python version and path. Without fail, this returns Python 2.7.5. What is required in the CMake file to get the version of Python at the PATH I am aiming for?