[Build] collect2: error: ld returned 1 exit status
Nacho-Neko opened this issue · comments
The error you encountered while using rust-arrayfire is "collect2: error: ld returned 1 exit status." To troubleshoot, you tried manually compiling with GCC using the following command:
gcc -lafcpu -L/opt/arrayfire/lib -I/opt/arrayfire/include -std=c++11 helloworld.cpp
.
This also resulted in the same error.
You have installed ArrayFire by compiling it, with the installation path at /opt/arrayfire,
using the command
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/arrayfire.
$LD_LIBRARY_PATH=/opt/arrayfire/lib
ll * /opt/arrayfire
total 28
drwxr-xr-x 7 root root 4096 Jan 15 18:29 ./
drwxr-xr-x 4 root root 4096 Jan 15 18:29 ../
drwxr-xr-x 2 root root 4096 Jan 15 18:29 LICENSES/
drwxr-xr-x 2 root root 4096 Jan 15 19:42 etc/
drwxr-xr-x 3 root root 4096 Jan 15 18:29 include/
drwxr-xr-x 2 root root 4096 Jan 15 19:42 lib/
drwxr-xr-x 3 root root 4096 Jan 15 18:29 share/
root@farm:/opt/arrayfire/share/ArrayFire/examples/helloworld# ll -d /opt/arrayfire
drwxr-xr-x 7 root root 4096 Jan 15 18:29 /opt/arrayfire/
root@farm:/opt/arrayfire/share/ArrayFire/examples/helloworld# ll * /opt/arrayfire
-rw-r--r-- 1 root root 12890 Jan 15 19:48 CMakeCache.txt
-rw-r--r-- 1 root root 796 Jan 15 07:42 CMakeLists.txt
-rw-r--r-- 1 root root 5438 Jan 15 20:18 Makefile
-rw-r--r-- 1 root root 1670 Jan 15 19:48 cmake_install.cmake
-rw-r--r-- 1 root root 1958 Jan 15 07:42 helloworld.cpp
-rwxr-xr-x 1 root root 26528 Jan 15 19:51 helloworld_cpu*
/opt/arrayfire:
total 28
drwxr-xr-x 7 root root 4096 Jan 15 18:29 ./
drwxr-xr-x 4 root root 4096 Jan 15 18:29 ../
drwxr-xr-x 2 root root 4096 Jan 15 18:29 LICENSES/
drwxr-xr-x 2 root root 4096 Jan 15 19:42 etc/
drwxr-xr-x 3 root root 4096 Jan 15 18:29 include/
drwxr-xr-x 2 root root 4096 Jan 15 19:42 lib/
drwxr-xr-x 3 root root 4096 Jan 15 18:29 share/
CMakeFiles:
total 68
drwxr-xr-x 5 root root 4096 Jan 15 20:18 ./
drwxr-xr-x 3 root root 4096 Jan 15 21:48 ../
drwxr-xr-x 3 root root 4096 Jan 15 19:48 3.22.1/
-rw-r--r-- 1 root root 676 Jan 15 19:48 CMakeDirectoryInformation.cmake
-rw-r--r-- 1 root root 24382 Jan 15 19:48 CMakeOutput.log
drwxr-xr-x 2 root root 4096 Jan 15 19:48 CMakeTmp/
-rw-r--r-- 1 root root 2022 Jan 15 20:18 Makefile.cmake
-rw-r--r-- 1 root root 3749 Jan 15 20:18 Makefile2
-rw-r--r-- 1 root root 238 Jan 15 20:18 TargetDirectories.txt
-rw-r--r-- 1 root root 85 Jan 15 20:18 cmake.check_cache
drwxr-xr-x 2 root root 4096 Jan 15 20:18 helloworld_cpu.dir/
-rw-r--r-- 1 root root 2 Jan 15 20:18 progress.marks
When I tried building the examples using cmake, it completed successfully, and I was able to run the build results without any issues.
I believe the key to solving the problem is figuring out how to make my GCC compile successfully.
Try to compile your program using g++
instead of gcc
. The former links slightly different libraries by default.