20160614:
I have glfw installed by MacPorts.
sudo port install glfw
And I have checked that /opt/local/lib/libglfw.dylib is exists.
Here is my top header of main.cpp:
#include <GLFW/glfw3.h>
My CMakeLists.txt(file1):
cmake_minimum_required (VERSION 2.8)
project (t1)
include_directories(/opt/local/include)
link_directories(/opt/local/lib)
# find_library(MYGLFWLIB NAMES glfw HINTS /opt/local/lib NO_DEFAULT_PATH)
set(GLLIBS GL glfw glew)
add_executable(t1 main.cpp)
target_link_libraries(t1 ${GLLIBS})
After cmake . && make which is no error reported, I execute by ./t1
Then Error came:
dyld: Library not loaded: lib/libglfw.3.dylib
Referenced from: /Users/...../t1
Reason: image not found
[1] 13949 trace trap ./t1
Then I use otool -L t1 to check lib dependens in t1
/opt/local/lib/libGL.1.dylib (compatibility version 4.0.0, current version 4.0.0)
lib/libglfw.3.dylib (compatibility version 3.0.0, current version 3.2.0)
/opt/local/lib/libGLEW.1.13.0.dylib (compatibility version 1.13.0, current version 1.13.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
Could someone tell me why glfw is not linked rightly?
20160615:
After modifying my CMakeLists.txt(file2):
cmake_minimum_required (VERSION 2.8)
project (t1)
include_directories(/opt/local/include)
link_directories(/opt/local/lib)
find_library(GL_LIB GL HINTS /opt/local/lib )
find_library(GLFW_LIB glfw HINTS /opt/local/lib)
find_library(GLEW_LIB glew HINTS /opt/local/lib)
message(${GLFW_LIB})
message(${GLEW_LIB})
message(${GL_LIB})
add_executable(t1 main.cpp)
target_link_libraries(t1 ${GL_LIB} ${GLFW_LIB} ${GLEW_LIB})
I have two osx device(MacMini and MacBookPro), the version of MacPorts and Xcode and CMake and System are all the same:
Mac osx : 10.11.5
MacPorts 2.3.4
CMake :3.5.2
Xcode: 7.3
Both version of CMakeLists (file1 and file2 above)works in MacMini, linker works fine.
But when it cames to my MacBookPro, glfw is not linked well.
Someone else had encounter the almost same problem:
macports-cmake-make-dyld-library-not-loaded
Is this problem SYSTEM VARIABLE concerned ?
After search for hours, I found the reason : glfw #3.2: install_name is not set properly
set(GLLIBS GL glfw glew)
That's not how you should use CMake. Use find_library or
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(simple ${GLFW_LIBRARIES})
Have a look into the documentation:
http://www.glfw.org/docs/3.0/build.html
Related
On my pc I have compiler gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0.
I would like to compile gstreamer source code, where is meson.build.
In meson.build, there is line:
cc = meson.get_compiler('c')
In user's path I set CC to gcc. When I start meson using command:
meson /path/to/directory I see that meson select gcc (gcc 8.1.0 "gcc (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0"). How can I change that?
I tried cc=gcc too.
My cpu is AMD 64bit.
I have Boost and Served REST API package installed in /opt/local.
Here's the "meaningful" part of my CmakeLists.txt:
find_package(PkgConfig REQUIRED)
pkg_check_modules(SERVED_PKG REQUIRED IMPORTED_TARGET served)
add_executable( rest_server rest_server.cpp )
target_link_libraries(rest_server PUBLIC PkgConfig::SERVED_PKG)
It does create an executable, and links it with the needed library.
However, it somehow fails to include the path to that library:
$ otool -L cmake-build-debug/rest_server
cmake-build-debug/rest_server:
libserved.1.4.dylib (compatibility version 0.0.0, current version 1.4.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 902.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
Which, when I try to run it via the CLion IDE, results in a failure to load the libserved.1.4.dylib library:
/Users/ur20980/src/security2/cmake-build-debug/rest_server
dyld: Library not loaded: libserved.1.4.dylib
Referenced from: /Users/ur20980/src/security2/cmake-build-debug/rest_server
Reason: image not found
Process finished with exit code 6
When I invoke the executable manually from the terminal, it seems to be OK:
$ cmake-build-debug/rest_server
Hello, World!
What is wrong???
I'm trying to build my own project that use LLVM. I downloaded the source code and the precompiled package on the official web site (last version).
http://releases.llvm.org/download.html
I downloaded :
LLVM source code
Clang for Windows (64-bit)
FYI, I don't build LLVM... only want to use it !
I followed the instruction here :
http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
in the section : "Embedding LLVM in your project"
So, I added this code :
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message("LLVM_INCLUDE_DIRS=${LLVM_INCLUDE_DIRS}")
message("LLVM_DEFINITIONS=${LLVM_DEFINITIONS}")
But I got several cmake error messages, here is my output :
-- Using LLVMConfig.cmake in: C:\\Luciad_src\\libs\\LLVM\\cmake\\modules
LLVM_INCLUDE_DIRS=
LLVM_DEFINITIONS=
CMake Error at C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:31 (list):
list sub-command REMOVE_ITEM requires two or more arguments.
Call Stack (most recent call first):
C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:256 (is_llvm_target_library)
components/query/CMakeLists.txt:15 (llvm_map_components_to_libnames)
Is there a problem with my script, or the packages I use ? Any idea ?
Thanks for your help
You can have the LLVM as binary or source package.
The binary package does not include CMake support. If you compare both installations (binary on the left, source after building and installing it on the right) you can see the difference:
LLVM-5.0.0-win64.exe
<=> llvm-5.0.1.src.tar.xz (build and installed)
So you need to build and install the source package first to get CMake support. On my Windows machine I needed a cmd shell with administrator rights, a Visual Studio installation, go to the downloaded and extracted sources and do:
> mkdir mybuilddir
> cd mybuilddir
> cmake ..
> cmake --build . --config Release --target INSTALL
If I now use your CMake example I get:
-- Found LLVM 5.0.1
-- Using LLVMConfig.cmake in: C:/Program Files (x86)/LLVM/lib/cmake/llvm
LLVM_INCLUDE_DIRS=C:/Program Files (x86)/LLVM/include
LLVM_DEFINITIONS=-DLLVM_BUILD_GLOBAL_ISEL -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Configuring done
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7 FATAL_ERROR)
INCLUDE(FindPackageHandleStandardArgs)
FIND_LIBRARY(GLOG_LIBRARY glog)
FIND_PATH(GLOG_INCLUDE_DIR "glog/logging.h")
SET(GLOG_LIBRARIES ${GLOG_LIBRARY})
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
Glog
REQUIRED_ARGS GLOG_INCLUDE_DIR GLOG_LIBRARY)
This is the cmake file. I installed the google glog 0.3.4 in the /apps/glog. Why when compiling this file, there is still the following error? I checked, glog/logging.h is under 0.3.4/include/glog/.
CMake Error at cmake/FindGlog.cmake:77 (MESSAGE):
Failed to find glog - Could not find glog include directory, set
GLOG_INCLUDE_DIR to directory containing glog/logging.h
Call Stack (most recent call first):
cmake/FindGlog.cmake:103 (GLOG_REPORT_NOT_FOUND)
CMakeLists.txt:27 (FIND_PACKAGE)
Glog now (at most four years after this question was asked) has CMake support! They have very good documentation here: https://github.com/google/glog#cmake
But this is the gist of what you should do:
cmake_minimum_required (VERSION 3.0.2)
project(myproj VERSION 1.0)
find_package(glog 0.6.0 REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE glog::glog)
Just like any other well-behaved, CMake-aware library!
As of November 18, 2017, official glog does not support CMake.
GitHub user sergiud added CMake support in a fork.
Please see the discussion in
https://github.com/google/glog/issues/4.
I builded a custom libobjc.A.dylib from the source of apple's open source website and I want to debug it by compiling a simple program with the dylib, but it seems the clang always using the system libobjc.A.dylib.
The compile command is:
xcrun --sdk macosx10.8 clang main.m -std=c99 -framework Foundation -lobjc -I./usr/include -L.
the libobjc.A.dylib is in the current folder. And the otool command tells me which library the program links with:
~ otool -L a.out
a.out:
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.18.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.19.0)
In the http://opensource.apple.com/source/objc4/objc4-551.1/test/test.pl file, it's using a flag called -fno-objc-link-runtime, but it seems it's not working with my laptop(mac 10.9.4, xcode 5.1.1)
Tried setting DYLD_LIBRARY_PATH environment var, but it's not working. Here is the folder which I compiled the code https://github.com/Jeswang/Compile-Issue, any suggestion or solution?
Actually, I used install_name_tool command to change the library's link:
install_name_tool -change /usr/lib/libobjc.A.dylib #executable_path/libobjc.A.dylib main
Useful links:
dyld manual
mikeash.com: Friday Q&A 2009-11-06: Linking and Install Names