Linker errors: libMagickWand-7.Q16HDRI.so.6: undefined reference(s)

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
User avatar
dan9er
Posts: 19
Joined: 2019-09-18T18:13:57-07:00
Authentication code: 1152
Location: Canada

Linker errors: libMagickWand-7.Q16HDRI.so.6: undefined reference(s)

Post by dan9er » 2019-10-12T10:41:21-07:00

I'm building my project that uses IM on Ubuntu 18.04 LTS, and I'm getting linker errors when I run make.

CLang++ version:

Code: Select all

$ clang++ --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Make version:

Code: Select all

$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
CMake version:

Code: Select all

$ cmake --version
cmake version 3.15.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.15)
project(cartogrtist)

# version
set(cartogrtist_VERSION_MAJOR 0)
set(cartogrtist_VERSION_MINOR 1)
set(cartogrtist_VERSION_PATCH 0)
set(cartogrtist_VERSION_DEV_BOOL 1)

# options
option(cartogrtist_DEBUG "Build with debug flags (for use with gdb and others)" OFF)
set(cartogrtist_MAGICK_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libMagick++-7.Q16HDRI.so
    CACHE FILEPATH "Location of the Magick++ .so file")
set(cartogrtist_NBT_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libnbt++.a
    CACHE FILEPATH "Location of the nbt++ .a file")

# compile with C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# set some stuff for Magick++ so it doesn't yell warnings at us
add_compile_definitions(MAGICKCORE_HDRI_ENABLE=0 MAGICKCORE_QUANTUM_DEPTH=8)

# add debugging flags?
if(cartogrtist_DEBUG)
    set(CMAKE_BUILD_TYPE RelWithDebInfo)
else()
    set(CMAKE_BUILD_TYPE Release)
endif()

# place final executable into bin/ instead of build/
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

# configure a header file to pass some of the CMake settings to the source code
configure_file(
    "${PROJECT_SOURCE_DIR}/src/cmakeVars.h.in"
    "${PROJECT_BINARY_DIR}/cmakeVars.h")
include_directories("${PROJECT_BINARY_DIR}")

# find all our .cpp and .h files and create a list of them
file(GLOB_RECURSE cartogrtist_SOURCES "${CMAKE_SOURCE_DIR}/src/*.cpp")
file(GLOB_RECURSE cartogrtist_HEADERS "${CMAKE_SOURCE_DIR}/src/*.h")
set (cartogrtist_INCLUDE_DIRS "")
foreach (_headerFile ${cartogrtist_HEADERS})
    get_filename_component(_dir ${_headerFile} PATH)
    list (APPEND cartogrtist_INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES cartogrtist_INCLUDE_DIRS)

# create the executable
add_executable(cartogrtist ${cartogrtist_SOURCES})

# set directories for libraries and includes
target_include_directories(cartogrtist PRIVATE ${cartogrtist_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include)
target_link_directories(cartogrtist PRIVATE ${CMAKE_SOURCE_DIR}/lib)

# link libraries to executable
target_link_libraries(cartogrtist ${cartogrtist_MAGICK_LIBRARY} ${cartogrtist_NBT_LIBRARY})
cartogrtist_MAGICK_LIBRARY is set to "cartogrtist/lib/libMagick++-7.Q16HDRI.so".
I'm not using find_package because CMake is dumb and doesn't want to find IM itself.

Console (irrelevant parts of directories stripped for privacy):

Code: Select all

cartogrtist/build$ make -j2
Scanning dependencies of target cartogrtist
[ 10%] Building CXX object CMakeFiles/cartogrtist.dir/src/block/block.cpp.o
[ 20%] Building CXX object CMakeFiles/cartogrtist.dir/src/cartogrtist.cpp.o
[ 30%] Building CXX object CMakeFiles/cartogrtist.dir/src/mapArt/mapArtFlat/mapArtFlat.cpp.o
[ 40%] Building CXX object CMakeFiles/cartogrtist.dir/src/mapArt/mapArtStaircase/mapArtStaircase.cpp.o
[ 50%] Building CXX object CMakeFiles/cartogrtist.dir/src/palette/palette.cpp.o
[ 60%] Building CXX object CMakeFiles/cartogrtist.dir/src/palette/paletteFlat/paletteFlat.cpp.o
[ 70%] Building CXX object CMakeFiles/cartogrtist.dir/src/palette/paletteStaircase/paletteStaircase.cpp.o
[ 80%] Building CXX object CMakeFiles/cartogrtist.dir/src/schematic/schematic.cpp.o
[ 90%] Building CXX object CMakeFiles/cartogrtist.dir/src/staircaseColumn/staircaseColumn.cpp.o
[100%] Linking CXX executable ../bin/cartogrtist
/usr/bin/ld: warning: libomp.so.5, needed by cartogrtist/lib/libMagickWand-7.Q16HDRI.so.6, not found (try using -rpath or -rpath-link)
cartogrtist/lib/libMagickWand-7.Q16HDRI.so.6: undefined reference to `GOMP_critical_name_end@VERSION'
cartogrtist/lib/libMagickWand-7.Q16HDRI.so.6: undefined reference to `omp_get_thread_num@VERSION'
cartogrtist/lib/libMagickWand-7.Q16HDRI.so.6: undefined reference to `omp_get_max_threads@VERSION'
cartogrtist/lib/libMagickWand-7.Q16HDRI.so.6: undefined reference to `omp_set_nested@VERSION'
cartogrtist/lib/libMagickWand-7.Q16HDRI.so.6: undefined reference to `GOMP_parallel@VERSION'
cartogrtist/lib/libMagickWand-7.Q16HDRI.so.6: undefined reference to `GOMP_critical_name_start@VERSION'
cartogrtist/lib/libMagickWand-7.Q16HDRI.so.6: undefined reference to `omp_get_num_threads@VERSION'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles/cartogrtist.dir/build.make:205: recipe for target '../bin/cartogrtist' failed
make[2]: *** [../bin/cartogrtist] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/cartogrtist.dir/all' failed
make[1]: *** [CMakeFiles/cartogrtist.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Relevent project tree:

Code: Select all

cartogrtist
├── bin
├── build
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   │   └── [CMake's stuff...]
│   ├── cmake_install.cmake
│   ├── cmakeVars.h
│   └── Makefile
├── CMakeFiles
│   └── [CMake's stuff...]
├── CMakeLists.txt
├── etc
│   └── ImageMagick-7
│       ├── colors.xml
│       ├── delegates.xml
│       ├── log.xml
│       ├── mime.xml
│       ├── policy.xml
│       ├── quantization-table.xml
│       ├── thresholds.xml
│       ├── type-apple.xml
│       ├── type-dejavu.xml
│       ├── type-ghostscript.xml
│       ├── type-urw-base35.xml
│       ├── type-windows.xml
│       └── type.xml
├── include
│   ├── libnbtplusplus
│   │   └── [other library's .h files...]
│   ├── Magick++
│   │   └── [Magick++'s .h files...]
│   ├── MagickCore
│   │   └── [MagickCore's .h files...]
│   ├── Magick++.h
│   ├── MagickWand
│   │   └── [MagickWand's .h files...]
│   └── tclap
│       └── [other library's .h files...]
├── lib
│   ├── ImageMagick-7.0.8
│   │   └── config-Q16HDRI
│   │       └── configure.xml
│   ├── libMagick++-7.Q16HDRI.a
│   ├── libMagick++-7.Q16HDRI.la
│   ├── libMagick++-7.Q16HDRI.so -> libMagick++-7.Q16HDRI.so.4.0.0
│   ├── libMagick++-7.Q16HDRI.so.4 -> libMagick++-7.Q16HDRI.so.4.0.0
│   ├── libMagick++-7.Q16HDRI.so.4.0.0
│   ├── libMagickCore-7.Q16HDRI.a
│   ├── libMagickCore-7.Q16HDRI.la
│   ├── libMagickCore-7.Q16HDRI.so -> libMagickCore-7.Q16HDRI.so.6.0.0
│   ├── libMagickCore-7.Q16HDRI.so.6 -> libMagickCore-7.Q16HDRI.so.6.0.0
│   ├── libMagickCore-7.Q16HDRI.so.6.0.0
│   ├── libMagickWand-7.Q16HDRI.a
│   ├── libMagickWand-7.Q16HDRI.la
│   ├── libMagickWand-7.Q16HDRI.so -> libMagickWand-7.Q16HDRI.so.6.0.0
│   ├── libMagickWand-7.Q16HDRI.so.6 -> libMagickWand-7.Q16HDRI.so.6.0.0
│   ├── libMagickWand-7.Q16HDRI.so.6.0.0
│   ├── libnbt++.a
│   └── pkgconfig
│       ├── ImageMagick-7.Q16HDRI.pc
│       ├── ImageMagick.pc
│       ├── Magick++-7.Q16HDRI.pc
│       ├── MagickCore-7.Q16HDRI.pc
│       ├── MagickCore.pc
│       ├── Magick++.pc
│       ├── MagickWand-7.Q16HDRI.pc
│       └── MagickWand.pc
└── src
    └── [project's .cpp and .h files...]

User avatar
magick
Site Admin
Posts: 11077
Joined: 2003-05-31T11:32:55-07:00

Re: Linker errors: libMagickWand-7.Q16HDRI.so.6: undefined reference(s)

Post by magick » 2019-10-12T11:20:59-07:00

It appears a dependency is missing, libgomp. Mod the Cmake configuration files to find libgomp and add it to the linker statement or disable OpenMP or build ImageMagick with autoconf/automake (e.g. run the `configure` script then `make`).

User avatar
dan9er
Posts: 19
Joined: 2019-09-18T18:13:57-07:00
Authentication code: 1152
Location: Canada

Re: Linker errors: libMagickWand-7.Q16HDRI.so.6: undefined reference(s)

Post by dan9er » 2019-10-18T16:54:56-07:00

magick wrote:
2019-10-12T11:20:59-07:00
It appears a dependency is missing, libgomp. Mod the Cmake configuration files to find libgomp and add it to the linker statement or disable OpenMP or build ImageMagick with autoconf/automake (e.g. run the `configure` script then `make`).
Well my ImageMagick setup was messy anyway, so I removed and recompiled it the standard way (in /usr/local/lib). OpenMP is listed as a feature and all tests pass.

New CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.15)
project(cartogrtist)

# version
set(cartogrtist_VERSION_MAJOR 0)
set(cartogrtist_VERSION_MINOR 1)
set(cartogrtist_VERSION_PATCH 0)
set(cartogrtist_VERSION_DEV_BOOL 1)

# options
set(cartogrtist_MAGICK_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libMagick++-7.Q16HDRI.so
CACHE FILEPATH "Location of the Magick++ library file")
set(cartogrtist_MAGICK_INCLUDE ${CMAKE_SOURCE_DIR}/include
CACHE PATH "Location of the ImageMagick .h files")
set(cartogrtist_NBT_LIBRARY ${CMAKE_SOURCE_DIR}/lib/libnbt++.a
CACHE FILEPATH "Location of the NBT++ library file")
set(cartogrtist_NBT_INCLUDE ${CMAKE_SOURCE_DIR}/include
CACHE PATH "Location of the NBT++ .h files")
set(cartogrtist_TCLAP_INCLUDE ${CMAKE_SOURCE_DIR}/include
CACHE PATH "Location of the TCLAP .h files")

# compile with C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# set some stuff for Magick++ so it doesn't yell warnings at us
add_compile_definitions(MAGICKCORE_HDRI_ENABLE=1 MAGICKCORE_QUANTUM_DEPTH=16)

# place final executable into bin/ instead of build/
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

# configure a header file to pass some of the CMake settings to the source code
configure_file(
    "${PROJECT_SOURCE_DIR}/src/cmakeVars.h.in"
    "${PROJECT_BINARY_DIR}/cmakeVars.h")
include_directories("${PROJECT_BINARY_DIR}")

# find all our .cpp and .h files and create a list of them
file(GLOB_RECURSE cartogrtist_SOURCES "${CMAKE_SOURCE_DIR}/src/*.cpp")
file(GLOB_RECURSE cartogrtist_HEADERS "${CMAKE_SOURCE_DIR}/src/*.h")
set (cartogrtist_INCLUDE_DIRS "")
foreach (_headerFile ${cartogrtist_HEADERS})
    get_filename_component(_dir ${_headerFile} PATH)
    list (APPEND cartogrtist_INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES cartogrtist_INCLUDE_DIRS)

# create the executable
add_executable(cartogrtist ${cartogrtist_SOURCES})

# set directories for libraries and includes
target_include_directories(cartogrtist PRIVATE ${cartogrtist_INCLUDE_DIRS} ${cartogrtist_MAGICK_INCLUDE} ${cartogrtist_NBT_INCLUDE} ${cartogrtist_TCLAP_INCLUDE})
target_link_directories(cartogrtist PRIVATE ${cartogrtist_MAGICK_LIBRARY} ${cartogrtist_NBT_LIBRARY})

# link libraries to executable
target_link_libraries(cartogrtist ${cartogrtist_MAGICK_LIBRARY} ${cartogrtist_NBT_LIBRARY})
cartogrtist_MAGICK_INCLUDE is set to /usr/local/include/ImageMagick-7
cartogrtist_MAGICK_LIBRARY is set to /usr/local/lib/libMagick++-7.Q16HDRI.a

Still getting linker errors though, a lot of them this time: https://pastebin.com/MwQkr2Vr
I think every IM .cpp file is complaining...

User avatar
dan9er
Posts: 19
Joined: 2019-09-18T18:13:57-07:00
Authentication code: 1152
Location: Canada

Re: Linker errors: libMagickWand-7.Q16HDRI.so.6: undefined reference(s)

Post by dan9er » 2019-11-01T14:44:50-07:00

Bump, still having this issue. This setup compiles on Windows 10 but not Linux.

Post Reply