Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot linking GDAL compiled from vcpkg #14632

Closed
epiciskandar opened this issue Nov 18, 2020 · 8 comments · Fixed by #13449
Closed

cannot linking GDAL compiled from vcpkg #14632

epiciskandar opened this issue Nov 18, 2020 · 8 comments · Fixed by #13449
Assignees
Labels
requires:repro The issue is not currently repro-able

Comments

@epiciskandar
Copy link

epiciskandar commented Nov 18, 2020

What am I doing?
trying using GDAL installed from vcpkg. the project is based on CMake.

How GDAL being installed

  1. get vcpkg whole git repo
  2. run ./bootstrap-vcpkg.sh
  3. execute "./vcpkg install GDAL"

What does the project look like
to make question simple, I reproduced with a test project:
./
|--CMakeLists.txt (1)
|--/build
|--/test
.....|--CMakeLists.txt (2)
.....|--test.cpp (3)

the file (1):

cmake_minimum_required(VERSION 3.4)
project(GD8)

set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_STANDARD 17)

add_subdirectory(test)

the file (2):

CMAKE_MINIMUM_REQUIRED(VERSION 3.4)
PROJECT(Test)

set(CMAKE_CXX_STANDARD 17)
AUX_SOURCE_DIRECTORY(. SRC_LIST)

SET(CMAKE_CXX_FLAGS "-std=c++1y")

find_package(GDAL)

ADD_EXECUTABLE(test test.cpp)
target_include_directories(test PRIVATE ${GDAL_INCLUDE_DIR})
target_link_libraries(test PRIVATE ${GDAL_LIBRARY} ${CMAKE_DL_LIBS})

the file (3):

#include <iostream>
#include "gdal.h"
#include "ogrsf_frmts.h"

int main()
{
    GDALDriverManager* driverManager = GetGDALDriverManager();
    GDALDriver* driver = driverManager->GetDriverByName("GPKG");
    GDALDatasetUniquePtr dataset(driver->Create("/test/test.gpkg", 0, 0, 0, GDT_Unknown, nullptr));
    return 0;
}

How to cmake and make

  1. cd build
  2. cmake --version
    3.18.4
  3. cmake .. -DCMAKE_TOOLCHAIN_FILE=/{to_vcpkg_dir}/scripts/buildsystems/vcpkg.cmake
-- Configuring done
-- Generating done
-- Build files have been written to: /{blah...}/build
  1. make test
(blah ...)
[ 50%] Building CXX object test/CMakeFiles/test.dir/test.cpp.o
(blah ...)
[100%] Linking CXX executable test

/usr/bin/g++-8.2  -std=c++1y   CMakeFiles/test.dir/test.cpp.o  -o test  -Wl,-rpath,/home/user/vcpkg/installed/x64-linux/lib /home/user/vcpkg/installed/x64-linux/lib/libgdal.so -ldl

/home/opt/compiler/gcc-8.2/gcc-8.2/bin/../lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: libcrypto.so.10, needed by /home/user/vcpkg/installed/x64-linux/lib/libgdal.so, not found (try using -rpath or -rpath-link)
/home/opt/compiler/gcc-8.2/gcc-8.2/bin/../lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: libsqlite3.so.0, needed by /home/user/vcpkg/installed/x64-linux/lib/libgdal.so, not found (try using -rpath or -rpath-link)
(bunch of above warnings here)

/home/opt/compiler/gcc-8.2/gcc-8.2/bin/../lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/user/vcpkg/installed/x64-linux/lib/libgdal.so: undefined reference to `sqlite3_bind_int'
/home/opt/compiler/gcc-8.2/gcc-8.2/bin/../lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/user/vcpkg/installed/x64-linux/lib/libgdal.so: undefined reference to `png_set_sRGB@PNG15_0'
/home/opt/compiler/gcc-8.2/gcc-8.2/bin/../lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /home/user/vcpkg/installed/x64-linux/lib/libgdal.so: undefined reference to `sqlite3_value_text'
(bunch of _undefined reference_ error here)

collect2: error: ld returned 1 exit status
make[3]: *** [test/test] Error 1
(blah ...)
make: *** [test] Error 2

What did I try

  1. search all the network
  2. rebuild/reinstall almost everything: cmake/vcpkg/GDAL/higher version gcc
  3. tried linking other libs, they are fine:fmt OpenSSL CURL ZLIB RapidJSON
  4. tried all things above on another machine, everything is fine
  5. manual linking those .so with target_link_libraries(), works. however, these manually linked .so continue complaining more undefined reference error needed by themselves
  6. all failing linking libs located in /usr/lib64
  7. with link_directories(/usr/lib64), no luck (yes, link_directories is before add_executable)

Environment
CentOS 7.8
gcc-8.2
cmake 3.17.3 (from dnf)
cmake 3.18.4 (from official website)
latest vcpkg
GDAL 2.4.1#13 from vcpkg

@JackBoosY JackBoosY added requires:more-information This Issue requires more information to solve requires:repro The issue is not currently repro-able labels Nov 19, 2020
@JackBoosY
Copy link
Contributor

I can't repro it using your sample code:

-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/usr/work/test
/home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -S/home/usr/work/test -B/home/usr/work/test --check-build-system CMakeFiles/Makefile.cmake 0
/home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -E cmake_progress_start /home/usr/work/test/CMakeFiles /home/usr/work/test/CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/usr/work/test'
make  -f CMakeFiles/sample.dir/build.make CMakeFiles/sample.dir/depend
make[2]: Entering directory '/home/usr/work/test'
cd /home/usr/work/test && /home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /home/usr/work/test /home/usr/work/test /home/usr/work/test /home/usr/work/test /home/usr/work/test/CMakeFiles/sample.dir/DependInfo.cmake --color=
Scanning dependencies of target sample
make[2]: Leaving directory '/home/usr/work/test'
make  -f CMakeFiles/sample.dir/build.make CMakeFiles/sample.dir/build
make[2]: Entering directory '/home/usr/work/test'
[ 50%] Building CXX object CMakeFiles/sample.dir/test.cpp.o
/usr/bin/c++   -I/home/usr/work/vcpkg/installed/x64-linux/include  -std=c++1y   -std=gnu++1z -o CMakeFiles/sample.dir/test.cpp.o -c /home/usr/work/test/test.cpp
[100%] Linking CXX executable sample
/home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/sample.dir/link.txt --verbose=1
/usr/bin/c++  -std=c++1y   CMakeFiles/sample.dir/test.cpp.o  -o sample  -Wl,-rpath,/home/usr/work/vcpkg/installed/x64-linux/lib /home/usr/work/vcpkg/installed/x64-linux/lib/libgdal.so -ldl
make[2]: Leaving directory '/home/usr/work/test'
[100%] Built target sample
make[1]: Leaving directory '/home/usr/work/test'
/home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -E cmake_progress_start /home/usr/work/test/CMakeFiles 0

Can you print the macro ${GDAL_LIBRARY} and provide it to me?

Thanks.

@epiciskandar
Copy link
Author

epiciskandar commented Nov 19, 2020

I can't repro it using your sample code:

-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/usr/work/test
/home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -S/home/usr/work/test -B/home/usr/work/test --check-build-system CMakeFiles/Makefile.cmake 0
/home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -E cmake_progress_start /home/usr/work/test/CMakeFiles /home/usr/work/test/CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/usr/work/test'
make  -f CMakeFiles/sample.dir/build.make CMakeFiles/sample.dir/depend
make[2]: Entering directory '/home/usr/work/test'
cd /home/usr/work/test && /home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /home/usr/work/test /home/usr/work/test /home/usr/work/test /home/usr/work/test /home/usr/work/test/CMakeFiles/sample.dir/DependInfo.cmake --color=
Scanning dependencies of target sample
make[2]: Leaving directory '/home/usr/work/test'
make  -f CMakeFiles/sample.dir/build.make CMakeFiles/sample.dir/build
make[2]: Entering directory '/home/usr/work/test'
[ 50%] Building CXX object CMakeFiles/sample.dir/test.cpp.o
/usr/bin/c++   -I/home/usr/work/vcpkg/installed/x64-linux/include  -std=c++1y   -std=gnu++1z -o CMakeFiles/sample.dir/test.cpp.o -c /home/usr/work/test/test.cpp
[100%] Linking CXX executable sample
/home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/sample.dir/link.txt --verbose=1
/usr/bin/c++  -std=c++1y   CMakeFiles/sample.dir/test.cpp.o  -o sample  -Wl,-rpath,/home/usr/work/vcpkg/installed/x64-linux/lib /home/usr/work/vcpkg/installed/x64-linux/lib/libgdal.so -ldl
make[2]: Leaving directory '/home/usr/work/test'
[100%] Built target sample
make[1]: Leaving directory '/home/usr/work/test'
/home/usr/work/vcpkg/downloads/tools/cmake-3.17.2-linux/cmake-3.17.2-Linux-x86_64/bin/cmake -E cmake_progress_start /home/usr/work/test/CMakeFiles 0

Can you print the macro ${GDAL_LIBRARY} and provide it to me?

Thanks.

with

find_package(GDAL)
message(STATUS "gdal variables: ${GDAL_LIBRARY} ${GDAL_INCLUDE_DIR}")

got

[cmake] -- gdal variables: optimized;/home/user/vcpkg/installed/x64-linux/lib/libgdal.so;debug;/home/user/vcpkg/installed/x64-linux/debug/lib/libgdal.so /home/user/vcpkg/installed/x64-linux/include

@JackBoosY
Copy link
Contributor

Does this issue related to #9068?

@JackBoosY JackBoosY removed the requires:more-information This Issue requires more information to solve label Nov 19, 2020
@epiciskandar
Copy link
Author

probably yes, I will figue this out. this may take much time

@JackBoosY
Copy link
Contributor

Maybe #13449 could fix this issue.

@epiciskandar
Copy link
Author

Does this issue related to #9068?

yes, I'm already figued out that my issue is completely related to this. glad to see we have plan to solve this.

Maybe #13449 could fix this issue.

thank you for all these helping information, but when would this pr could be merged, it looks taking much time already.

@JackBoosY
Copy link
Contributor

@epiciskandar As soon as possible.

@JackBoosY JackBoosY linked a pull request Nov 20, 2020 that will close this issue
@JackBoosY JackBoosY reopened this Nov 20, 2020
@JackBoosY
Copy link
Contributor

Please wait for #13449 merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires:repro The issue is not currently repro-able
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants