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

Missing -fPIC in nvcc host compiler. #186

Closed
bartoszek opened this issue Jul 23, 2017 · 5 comments
Closed

Missing -fPIC in nvcc host compiler. #186

bartoszek opened this issue Jul 23, 2017 · 5 comments

Comments

@bartoszek
Copy link

bartoszek commented Jul 23, 2017

Enconture small problem while building dense_stereo on linux (arch_linux,gcc_7.1,cmake_3.8.1,cuda_8.0,cuda_host_compiler=gcc5_5.4.0)
linker complains about missing -fPIC flag in libmvs.a

/usr/bin/ld: ../mvs/libmvs_cuda.a(mvs_cuda_generated_patch_match_cuda.cu.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ../mvs/libmvs_cuda.a(mvs_cuda_generated_gpu_mat_prng.cu.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ../mvs/libmvs_cuda.a(mvs_cuda_generated_gpu_mat_ref_image.cu.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[2]: *** [src/exe/CMakeFiles/dense_stereo.dir/build.make:163: src/exe/dense_stereo] Błąd 1
make[1]: *** [CMakeFiles/Makefile2:441: src/exe/CMakeFiles/dense_stereo.dir/all] Błąd 2
make[1]: *** Oczekiwanie na niezakończone zadania....

Adding --compiler-options -fPIC to CUDA_NVCC_FLAGS fixes the issue for me.

@ahojnnes
Copy link
Contributor

Thanks for the feedback. Did you change anything in CMake or why are you building shared library objects?

@bartoszek
Copy link
Author

bartoszek commented Jul 24, 2017

I'm using default arch_linux build environment. The problem may relate to CMake=3.8 FindCUDA appending -fPIC to CFLAGS. ( Nope.. without cuda installed `-fPIC' still get added across the board ).
What I found in cmake build directory.

CMakeFiles/mvs_cuda.dir/flags.make:CXX_FLAGS = -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -g -fvar-tracking-assignments -g -fvar-tracking-assignments -std=c++11 -Wno-maybe-uninitialized -fopenmp -O3 -DNDEBUG -fPIC   -Wall -pedantic` 
CMakeFiles/mvs.dir/flags.make:CXX_FLAGS = -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -g -fvar-tracking-assignments -g -fvar-tracking-assignments -std=c++11 -Wno-maybe-uninitialized -fopenmp -O3 -DNDEBUG -fPIC   -Wall -pedantic -fPIC -std=gnu++11

Another possible cnadidate for forcing fPIC could be QT5:
/usr/lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake

 57 # Targets using Qt need to use the POSITION_INDEPENDENT_CODE property. The
 58 # Qt5_POSITION_INDEPENDENT_CODE variable is used in the # qt5_use_module
 59 # macro to add it.
 60 set(Qt5_POSITION_INDEPENDENT_CODE True)
 61
 62 # On x86 and x86-64 systems with ELF binaries (especially Linux), due to
 63 # a new optimization in GCC 5.x in combination with a recent version of
 64 # GNU binutils, compiling Qt applications with -fPIE is no longer
 65 # enough.
 66 # Applications now need to be compiled with the -fPIC option if the Qt option
 67 # "reduce relocations" is active. For backward compatibility only, Qt accepts
 68 # the use of -fPIE for GCC 4.x versions.
 69 if (CMAKE_VERSION VERSION_LESS 2.8.12
 70         AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
 71         OR CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0))
 72     set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE "ON")
 73 else()
 74     set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_OPTIONS -fPIC)
 75 endif()
 76

As I can understand, qt is forcing fpic when building with gcc<=5.0, which is current host compiler for cuda on arch.

@ahojnnes
Copy link
Contributor

Can you check whether adding list(APPEND CUDA_NVCC_FLAGS "--compiler-options -fPIC") after line 175 in the CMakeLists.txt file resolves the problem? Thanks!

@bartoszek
Copy link
Author

Works here.

@ahojnnes
Copy link
Contributor

ahojnnes commented Aug 1, 2017

Thanks, fixed in the dev branch now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants