arrow icon indicating copy to clipboard operation
arrow copied to clipboard

Undefined reference

Open s-simoncelli opened this issue 2 years ago • 13 comments

Hello

I have been having issues linking arrow when compiled from source or using msys64 for a C++ project:

  [2/2] Linking CXX executable test_project.exe
  FAILED: test_project.exe 
  cmd.exe /C "cd . && C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\mingw\bin\g++.exe -g  CMakeFiles/test_project.dir/main.cpp.obj -o test_project.exe -Wl,--out-implib,libtest_project.dll.a -Wl,--major-image-version,0,--minor-image-version,0  "C:/Program Files/arrow/lib/arrow_static.lib"  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
  C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\mingw\bin/ld.exe: CMakeFiles/test_project.dir/main.cpp.obj:C:/Users/netce/CLionProjects/untitled/main.cpp:5: undefined reference to `arrow::int16()'
  collect2.exe: error: ld returned 1 exit status
  ninja: build stopped: subcommand failed.

My CMakeLists.txt file is:

cmake_minimum_required(VERSION 3.23)
project(test_project)

set(CMAKE_CXX_STANDARD 14)

#set(CMAKE_PREFIX_PATH "C:/msys64/mingw64")
include_directories(C:/Program Files/arrow)
#include_directories(C:/msys64/mingw64)
find_package(Arrow REQUIRED)
if (Arrow_FOUND)
    message(STATUS "Found Apache Arrow ${ARROW_VERSION}")
else()
    message(FATAL_ERROR "Could NOT find Apache Arrow")
endif()

add_executable(test_project main.cpp)
target_link_libraries(test_project PRIVATE arrow_static)
#target_link_libraries(test_project PRIVATE arrow_shared)

and my main.cpp is:

#include <iostream>
#include <arrow/type_fwd.h>

int main() {
    arrow::int16();

    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Can anybody help me out?

Thanks

s-simoncelli avatar Oct 09 '22 07:10 s-simoncelli

Could you share the full output of your cmake ... command?

kou avatar Oct 09 '22 22:10 kou

The command is

C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/Users/netce/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35/bin/ninja/win/ninja.exe -G Ninja -S C:\Users\netce\CLionProjects\untitled -B C:\Users\netce\CLionProjects\untitled\cmake-build-debug

s-simoncelli avatar Oct 10 '22 05:10 s-simoncelli

Could you also show the output of the command?

kou avatar Oct 11 '22 00:10 kou

This is the output

  C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/Users/netce/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35/bin/ninja/win/ninja.exe -G Ninja -S C:\Users\netce\CLionProjects\untitled -B C:\Users\netce\CLionProjects\untitled\cmake-build-debug
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Users/netce/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35/bin/mingw/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Users/netce/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35/bin/mingw/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using the multi-header code from C:/Users/netce/CLionProjects/untitled/cmake-build-debug/_deps/json-src/include/
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found Apache Arrow 9.0.0
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/netce/CLionProjects/untitled/cmake-build-debug

s-simoncelli avatar Oct 11 '22 05:10 s-simoncelli

Thanks.

How did you install your Apache Arrow into C:\Program Files\arrow? It seems that you used Visual C++ not MSYS2 (what is msys64?).

Could you also show file list in C:\Program Files\arrow\lib\?

kou avatar Oct 11 '22 05:10 kou

I used Visual Studio C++:

"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64
cd cpp
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A x64  -DARROW_BUILD_TESTS=OFF  -DARROW_BUILD_EXAMPLES=OFF -DARROW_BUILD_UTILITIES=ON -DARROW_CSV=ON
cmake --build . --target install --config Release

It compiled successfully producing the following:

   Directory: C:\Program Files\arrow\lib


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        10/10/2022     06:44                cmake
d-----        10/10/2022     06:44                pkgconfig
-a----        10/10/2022     06:44        2565964 arrow.lib
-a----        10/10/2022     06:42       49050442 arrow_static.lib

However arrow.dll is in the bin folder.

I also tried with the package available in MSYS2

s-simoncelli avatar Oct 11 '22 05:10 s-simoncelli

Thanks.

Did you get the same error with the package in MSYS2? ( https://packages.msys2.org/package/mingw-w64-ucrt-x86_64-arrow?repo=ucrt64 )

Could you try adding target_compile_definitions(test_project PRIVATE ARROW_STATIC)? Or could you try using arrow_shared instead of arrow_static?

kou avatar Oct 11 '22 06:10 kou

I did try using both the shared and static version, but I always get the same error. Unfortunately adding the compile definition didn't help.

Using MSYS2 throws more errors:

FAILED: test_project.exe 
cmd.exe /C "cd . && C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\mingw\bin\g++.exe -g  CMakeFiles/test_project.dir/main.cpp.obj -o test_project.exe -Wl,--out-implib,libtest_project.dll.a -Wl,--major-image-version,0,--minor-image-version,0  C:/msys64/mingw64/lib/libarrow.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\mingw\bin/ld.exe: C:/msys64/mingw64/lib/libarrow.a(unity_5_cxx.cxx.obj):(.rdata$.refptr.__emutls_v._ZSt11__once_call[.refptr.__emutls_v._ZSt11__once_call]+0x0): undefined reference to `__emutls_v._ZSt11__once_call'
C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\mingw\bin/ld.exe: C:/msys64/mingw64/lib/libarrow.a(unity_5_cxx.cxx.obj):(.rdata$.refptr.__emutls_v._ZSt15__once_callable[.refptr.__emutls_v._ZSt15__once_callable]+0x0): undefined reference to `__emutls_v._ZSt15__once_callable'
C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\mingw\bin/ld.exe: C:/msys64/mingw64/lib/libarrow.a(unity_13_cxx.cxx.obj):(.text+0xde5): undefined reference to `inflateEnd'
....
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

s-simoncelli avatar Oct 12 '22 05:10 s-simoncelli

OK. Let's use arrow_shared from MSYS2 as the first step.

Could you show all build logs including cmake ... for arrow_shared from MSYS2.

I tried arrow_shared from MSYS2 with MSYS2's CMake, Ninja, GCC and son. And it worked.

kou avatar Oct 12 '22 07:10 kou

$ cmake -S . -B cpp.build
-- Building for: Ninja
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/ucrt64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/ucrt64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Checking for modules 'libbrotlicommon;libbrotlienc;libbrotlidec'
--   Found libbrotlicommon, version 1.0.9
--   Found libbrotlienc, version 1.0.9
--   Found libbrotlidec, version 1.0.9
-- Found Brotli: C:/msys64/ucrt64/lib/libbrotlicommon.dll.a  
-- Found OpenSSL: C:/msys64/ucrt64/lib/libcrypto.dll.a (found version "1.1.1q")  
-- Checking for module 'thrift'
--   Found thrift, version 0.13.0
-- Found Thrift: C:/msys64/ucrt64/lib/libthrift.a (found version "0.13.0")  
-- Found Protobuf: C:/msys64/ucrt64/lib/libprotobuf.dll.a (found version "3.16.0") 
-- Found ZLIB: C:/msys64/ucrt64/lib/libz.dll.a (found version "1.2.12") 
CMake Warning at C:/msys64/ucrt64/lib/cmake/arrow/Findlz4Alt.cmake:25 (find_package):
  By not providing "Findlz4.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "lz4", but
  CMake did not find one.

  Could not find a package configuration file provided by "lz4" with any of
  the following names:

    lz4Config.cmake
    lz4-config.cmake

  Add the installation prefix of "lz4" to CMAKE_PREFIX_PATH or set "lz4_DIR"
  to a directory containing one of the above files.  If "lz4" provides a
  separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
  C:/msys64/ucrt64/share/cmake/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  C:/msys64/ucrt64/lib/cmake/arrow/ArrowConfig.cmake:87 (find_dependency)
  CMakeLists.txt:9 (find_package)


-- Checking for module 'liblz4'
--   Found liblz4, version 1.9.3
-- Found lz4Alt: C:/msys64/ucrt64/lib/liblz4.dll.a  
-- Checking for module 'libzstd'
--   Found libzstd, version 1.5.2
-- Found zstd: C:/msys64/ucrt64/lib/libzstd.dll.a  
-- Found BZip2: C:/msys64/ucrt64/lib/libbz2.dll.a (found version "1.0.8") 
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Found utf8proc: C:/msys64/ucrt64/lib/libutf8proc.dll.a (found version "2.7.0") 
-- Found c-ares: C:/msys64/ucrt64/lib/cmake/c-ares/c-ares-config.cmake (found version "1.18.1")       
-- Found Apache Arrow 9.0.0
-- Configuring done
-- Generating done
$  cmake --build cpp.build
-- Build files have been written to: C:/Users/kou/tmp/cpp.build
[2/2] Linking CXX executable test_project.exe
$

kou avatar Oct 12 '22 07:10 kou

This is the log for cmake:

C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=C:/Users/netce/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35/bin/ninja/win/ninja.exe -G Ninja -S C:\Users\netce\CLionProjects\untitled -B C:\Users\netce\CLionProjects\untitled\cmake-build-debug
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Users/netce/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35/bin/mingw/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Users/netce/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35/bin/mingw/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Checking for modules 'libbrotlicommon;libbrotlienc;libbrotlidec'
--   Found libbrotlicommon, version 1.0.9
--   Found libbrotlienc, version 1.0.9
--   Found libbrotlidec, version 1.0.9
-- Found Brotli: C:/msys64/mingw64/lib/libbrotlicommon.dll.a  
-- Found OpenSSL: C:/msys64/mingw64/lib/libcrypto.dll.a (found version "1.1.1q")  
-- Checking for module 'thrift'
--   Found thrift, version 0.13.0
-- Found Thrift: C:/msys64/mingw64/lib/libthrift.a (found version "0.13.0")  
-- Found Protobuf: C:/msys64/mingw64/lib/libprotobuf.dll.a (found version "3.21.5") 
-- Found ZLIB: C:/msys64/mingw64/lib/libz.dll.a (found version "1.2.12") 
CMake Warning at C:/msys64/mingw64/lib/cmake/arrow/Findlz4Alt.cmake:25 (find_package):
  By not providing "Findlz4.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "lz4", but
  CMake did not find one.

  Could not find a package configuration file provided by "lz4" with any of
  the following names:

    lz4Config.cmake
    lz4-config.cmake

  Add the installation prefix of "lz4" to CMAKE_PREFIX_PATH or set "lz4_DIR"
  to a directory containing one of the above files.  If "lz4" provides a
  separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
  C:/Users/netce/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35/bin/cmake/win/share/cmake-3.23/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  C:/msys64/mingw64/lib/cmake/arrow/ArrowConfig.cmake:87 (find_dependency)
  CMakeLists.txt:10 (find_package)


-- Checking for module 'liblz4'
--   Found liblz4, version 1.9.4
-- Found lz4Alt: C:/msys64/mingw64/lib/liblz4.dll.a  
-- Checking for module 'libzstd'
--   Found libzstd, version 1.5.2
-- Found zstd: C:/msys64/mingw64/lib/libzstd.dll.a  
-- Found BZip2: C:/msys64/mingw64/lib/libbz2.dll.a (found version "1.0.8") 
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Found utf8proc: C:/msys64/mingw64/lib/libutf8proc.dll.a (found version "2.7.0") 
-- Found c-ares: C:/msys64/mingw64/lib/cmake/c-ares/c-ares-config.cmake (found version "1.18.1") 
-- Found Apache Arrow 9.0.0
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/netce/CLionProjects/untitled/cmake-build-debug

C:\Users\netce\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\222.4167.35\bin\cmake\win\bin\cmake.exe --build C:\Users\netce\CLionProjects\untitled\cmake-build-debug --target test_project -j 6
[1/2] Building CXX object CMakeFiles/test_project.dir/main.cpp.obj
[2/2] Linking CXX executable test_project.exe

Now it links but when I run, it exists with

 Process finished with exit code -1073741515 (0xC0000135)

Where is the ddl stored?

s-simoncelli avatar Oct 12 '22 11:10 s-simoncelli

You need to add C:\msys64\mingw64\bin to your PATH. There is libarrow.dll in the folder.

kou avatar Oct 12 '22 21:10 kou

The folder does contain the DLL but the exe still does not run:

Process finished with exit code -1073741511 (0xC0000139)

s-simoncelli avatar Oct 16 '22 10:10 s-simoncelli