I am trying to compile my project on macOS with CMake. I have gstreamer installed via brew and I can access the include directory. For example this is the include directoy for gstreamer:
/usr/local/Cellar/gstreamer/1.16.2/include/gstreamer-1.0/
When running cmake with following CMakeLists.txt everything runs successfully, but make fails when I trying to link with following error:
[ 25%] Linking CXX executable multiviewer
ld: library not found for -lgstreamer-1.0
CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(application)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Core REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5WebSockets REQUIRED)
# Required for GStreamer
find_package(PkgConfig)
# Look for GStreamer installation
pkg_check_modules(GST REQUIRED gstreamer-1.0)
add_executable(application
main.cpp qml.qrc server.cpp server.h
${PROTO_SRCS} ${PROTO_HDRS} client.cpp client.h)
# Qt5
target_link_libraries(application Qt5::Core Qt5::Quick Qt5::WebSockets)
# GStreamer
target_include_directories(application PUBLIC ${GST_INCLUDE_DIRS})
target_compile_options(application PUBLIC ${GST_CFLAGS})
target_link_libraries(application ${GST_LIBRARIES})
Here are the packages I've installed:
brew install pkg-config
brew install gstreamer
brew install gst-plugins-base
brew install gst-plugins-good
brew install gst-plugins-bad
brew install gst-plugins-ugly
brew install gst-libav
Output of pkg-config --cflags gstreamer-1.0:
-I/usr/local/Cellar/libffi/3.2.1/lib/libffi-3.2.1/include -I/usr/local/Cellar/gstreamer/1.16.2/include/gstreamer-1.0 -I/usr/local/Cellar/glib/2.62.4/include -I/usr/local/Cellar/glib/2.62.4/include/glib-2.0 -I/usr/local/Cellar/glib/2.62.4/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.43/include
Output of pkg-config --libs gstreamer-1.0:
-L/usr/local/Cellar/gstreamer/1.16.2/lib -L/usr/local/Cellar/glib/2.62.4/lib -L/usr/local/opt/gettext/lib -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0 -lintl
Do I need something else to install or what am I doing wrong?
The error:
ld: library not found for -lgstreamer-1.0
indicates that the library gstreamer-1.0 was passed to the linker, but the linker doesn't know where to find it (likely because it does not reside in the typical system paths). It is up to CMake to provide the full path to the GST libraries. From the pkg_check_modules documentation, here are some of the library-related variables populated for a generic package XXX:
<XXX>_LIBRARIES:
only the libraries (without the ā-lā)
<XXX>_LINK_LIBRARIES:
the libraries and their absolute paths
<XXX>_LIBRARY_DIRS:
the paths of the libraries (without the ā-Lā)
The GST_LIBRARIES variable will only list the library names (gstreamer-1.0;gobject-2.0;glib-2.0;intl), but in this case, we need to provide the library paths as well. So, change the target_link_libraries() call to use GST_LINK_LIBRARIES:
target_link_libraries(application PUBLIC ${GST_LINK_LIBRARIES})
Related
when I execute
./configure
...
checking for libxml-2.0... no
configure: error: Library libxml2 not found, install library or build without (using --disable-xml).
I installed libxml2 with brew and checked a lot of articles, but nothing helped so far.
UPDATE
./configure --help
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
libxml2_CFLAGS
C compiler flags for libxml2, overriding pkg-config
libxml2_LIBS
linker flags for libxml2, overriding pkg-config
homebrew installs libxml2 as "keg only" which means it is not symlinked to the normal /usr/local/include and /usr/local/lib directories... which means nothing can find it without help. You can get all the above info by running:
brew info libxml2
If you run:
brew ls libxml2
it will tell you the full paths to all the files in that package.
If you also run:
./configure --help
it should tell you what environment variables you need to set in order to find libxml2 So, armed with these last two pieces of info, you should be able to work out what you need to set and how.
I note there is a pkg-config file listed for libxml2 by homebrew at:
/usr/local/Cellar/libxml2/2.9.10/lib/pkgconfig/libxml-2.0.pc
which is also available via a non-version-specific symlink as:
/usr/local/opt/libxml2/lib/pkgconfig/libxml-2.0.pc
so, if you have installed pkg-config with homebrew, like this:
brew install pkg-config
the solution may be just to add the path for that to your PKG_CONFIG_PATH with:
export PKG_CONFIG_PATH=/usr/local/opt/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH
and then to rerun your configure script.
Note: It is only after installing pkg-config (via brew) that homebrew will display pkg-config related "caveats" for many affected packages e.g. libffi:
==> Caveats
libffi is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.
For compilers to find libffi you may need to set:
export LDFLAGS="-L/usr/local/opt/libffi/lib"
For pkg-config to find libffi you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
Unfortunately, however, this appears not to be the case for libxml2 for some reason. (Related homebrew issue: "libxml2 install path".)
I have boost 1.53 which was installed by yum. But I need to built my application required boost version 1.64. So I built boost 1.64 and installed with prefix /usr/local. The boost version detected by CMake is 1.64 (shown is message generated by CMake). But when I use ldd to check, its is version 1.53
I tried to reproduce the problem by create a small project and create a simple boost test linking to Boost::unit_test_framework. But it linking to the correct Boost version. When I looking in to link.txt of the executable, I saw that line:
c++ -g main.cpp.o -o Test -Wl,-rpath,/usr/local/lib /usr/local/lib/libboost_unit_test_framework.so
But in my main projects, it was
c++ -g -o ...... -lnsl -lrt -lboost_program_option -lboost_filesystem -lboost_thread
I check ld search path by this command:
$ gcc -m64 -Xlinker --verbose 2>/dev/null | grep SEARCH | sed 's/SEARCH_DIR("=\?\([^"]\+\)"); */\1\n/g' | grep -vE '^$'
and the result is:
/usr/local/lib64
/lib64
/usr/lib64
/usr/local/lib
......
The boost 1.53 install path is /lib64 and the install path of 1.64 is /usr/local/lib. So I think the test version is correct because of boost's absolute path is specified. And if the absolute path is not specified, ld will use version 1.53 because it was located first.
I tried set BOOT_ROOT and Boost_NO_SYSTEM_PATHS but can't solve this problem.
Update: I found the problem. The original cmake file was look like this:
find_package(Boost 1.64 REQUIRED COMPONENTS program_options)
target_link_library(MyProgram PRIVATE Boost::program_options) #original cmake
#target_link_library(MyProgram PRIVATE boost_program_options) #my cmake
#target_link_library(MyProgram PRIVATE ${Boost_LIBRARIES}) #fixed cmake
I fix the cmake because I can not run cmake with original cmake. cmake told me that Boost:program_options was not found on my computer. When I replace with boost_program_options, then it work but this library is not result of find_package.
I've been trying to compile the FileZilla versions 3.11 and 3.24 on Mac for a research project but when I run ../configure I get the following error:
configure: error: libgnutls 3.1.12 greater was not found. You can get it from http://gnutls.org/
However, I've installed gnutls using homebrew; when I run
brew list gnutls
I can see the library installed at /usr/local/Cellar/gnutls/3.5.8/
Any ideas to resolve the problem are appreciated. Thanks
Updated Answer
It seems that GNUtls, as installed by homebrew ships with a pkgconfig file. So, you need to install pkgconfig if you don't have it already using:
brew install pkgconfig
Then, once you have that, you can find the compiler include file settings with:
pkg-config --cflags gnutls
Sample Output
-I/usr/local/Cellar/gnutls/3.5.8/include -I/usr/local/Cellar/nettle/3.3/include -I/usr/local/Cellar/libtasn1/4.10/include -I/usr/local/Cellar/p11-kit/0.23.3/include/p11-kit-1
And the linker library settings with:
pkg-config --libs gnutls
Sample Output
-L/usr/local/Cellar/gnutls/3.5.8/lib -lgnutls
So, we (just) need to convey that information to FileZilla. So, first we run:
./configure --help | grep -i utls
Sample Output
--enable-gnutlssystemciphers
Enables the use of gnutls system ciphers.
LIBGNUTLS_CFLAGS
C compiler flags for LIBGNUTLS, overriding pkg-config
LIBGNUTLS_LIBS
linker flags for LIBGNUTLS, overriding pkg-config
So it looks like we need to do something like:
export LIBGNUTLS_CFLAGS=$(pkg-config --cflags gnutls)
export LIBGNUTLS_LIBS=$(pkg-config --libs gnutls)
./configure
Original Answer
I haven't tried this with FileZilla, but I use it with other packages, and there is nothing to lose...
If homebrew has installed your GNUtls in /usr/local/Cellar/gnutls/3.5.8/, you could try telling FileZilla that location in your configure like this:
./configure CPPFLAGS="-I/usr/local/Cellar/gnutls/3.5.8/include" LDFLAGS="-L/usr/local/Cellar/gnutls/3.5.8/lib" ... other flags
I need to use OpenGL as a library in my project on my Ubuntu 15.04 64bit PC, which is built by CMake 3.0.2. I install packages: mesa-common-dev mesa-utils-extra libgl1-mesa-dev libglu1-mesa-dev libglapi-mesa libx11-dev libxi-dev libxinerama-dev libxcursor-dev libxrandr-dev
After run cmake and Makefile, I got these link error:
/usr/bin/ld: /home/user/CMU462/DrawSVG/asst1_drawsvg/lib/libglfw.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libX11.so: error adding symbols: DSO missing from command line
I checked /usr/lib/x86_64-linux-gnu/libX11.so, it does exist.
I found a explanation, it seems I failed to link my project with X11 library. The answer says that add -lX11 option may fix this.
Alternatively I link
X11 library in CMakeLists.txt according to FindX11.cmake:
find_package(X11 REQUIRED)
message(STATUS "X11_FOUND = ${X11_FOUND}")
message(STATUS "X11_INCLUDE_DIR = ${X11_INCLUDE_DIR}")
message(STATUS "X11_LIBRARIES = ${X11_LIBRARIES}")
include_directories(${X11_INCLUDE_DIR})
link_directories(${X11_LIBRARIES})
target_link_libraries(MyProj ... ${X11_LIBRARIES})
Run cmake I got these output:
-- X11_FOUND = 1
-- X11_INCLUDE_DIR = /usr/include
-- X11_LIBRARIES = /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
But I still got the error aforementioned.
QUESTION: The X11 library can be linked by
using target_link_libraries in CMakeLists.txt, or
adding -lX11 option directly to compiling command
What's the difference between them? Does the link in CMakeLists.txt directly lead to a -lX11 option in Makefile generated?
If so, did I do something wrong in CMakeLists.txt?
UPDATE
Let's take this project as example, following is my build procedure.
Install required libraries: Install the OpenGL and other relative libraries (the GLEW and GLFW library is provided in this project): mesa-common-dev mesa-utils-extra libgl1-mesa-dev libglu1-mesa-dev libglapi-mesa libxi-dev libxinerama-dev libxcursor-dev libxrandr-dev
Run CMake: Then use the provided CMakeLists.txt, everything goes right.
Make: When make the project, this error occurred:
/usr/bin/ld: /home/user/CMU462/DrawSVG/asst1_drawsvg/lib/libglfw.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libX11.so: error adding symbols: DSO missing from command line
I have searched for many times, all of the answers say that the incorrect link of glfw3 and x11 lead to the error:
missing the -X11 option. However in line 26 of CMakeLists.txt exists this option
the libraries show arranged in order. I check the dependencies with pkg-config --libs command, all libraries are arranged in order in line 17 to 29 of CMakeLists.txt.
The only potential reason for this is the order of the compile options of libraries (line 17 to 29) and the target_link_libraries (line 116) of CMakeLists.txt.
Otherwise, there must be another error omitted by me during my procedure.
On OS X 10.8.2, I have macports and have installed:
glib2
pkg-config
among other things. The cmake I run tries to use pkg-config to find glib2. Running pkg-config --libs glib-2.0:
-L/opt/local/lib -lglib-2.0 -lintl
and --cflags:
-I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include
Yet, when I try to enter these in (individually, or all of them using ; or :), and all sorts of combinations, or when I tried downloading gtk and using the glib2 dirs of that: cmake complains it can't find the directories:
checking for module 'gstreamer-0.10'
found gstreamer-0.10, version 0.10.36
checking for module 'glib-2.0'
found glib-2.0, version 2.34.3
CMake Error at /Applications/CMake 2.8-10.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (message):
Could NOT find GLib2 (missing: GLIB2_LIBDIR GLIB2_INCLUDE_DIRS)
Call Stack (most recent call first):
/Applications/CMake 2.8-10.app/Contents/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:291 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindGLib2.cmake:127 (find_package_handle_standard_args)
cmake/Modules/FindGStreamer.cmake:12 (find_package)
CMakeLists.txt:32 (find_package)
I saw this page about conflicting pkg-config's with MonoDevelop. I uninstalled Mono, don't have any other pkg-config binaries that I can find, and cleared the cmake cache without any luck. I've looked at the cmake specifics, and its looking for glib.h and glibconfig.h, which are in those directories. Why can't it just behave?
Try to use this file: http://svn.opensync.org/branches/3rd-party-cmake-modules/modules/FindGLIB2.cmake
In your main CMakeLists.txt file, enter the following line:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/helper/")
This is assuming that the above FindGLIB2.cmake is stored in directory /helper off the src.
The contents of this file will help CMake to better find GLIB2.
This link will help you understand how these files work: http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries#Writing_find_modules
I faced this problem while building wireshark-3.4.2 from source using cmake on Centos8.2/RHEL8.2. The error was
Could NOT find GLIB2 (missing: GLIB2_LIBRARY GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR) Required is at least version "2.32.0")
while my system had preinstalled glib-2.56.4
Solution: Installed glib2-devel package. Then cmake found the glib-2.0 properly.
The cmake output looked like:
-- Checking for one of the modules 'glib-2.0'
-- Found GLIB2: /usr/lib64/libglib-2.0.so (found suitable version "2.56.4", minimum required is "2.32.0")