Community
Participate
Working Groups
Using the "Shared Library Managed build Project" on Linux using GCC (aka g++). The "Position Independent Compilation" flag which is required only when compiling for shared libraries is missing in the g++ command generated by Eclipse CDT. Could not find an option is Preferences for setting this flag. I hope this isn't a user error and there is someway to specify that option only for Shared Library Builds, and not for all g++ builds. === copy of console log ==== 08:25:52 **** Build of configuration Release for project MyThrow **** make all Building file: ../mythrow.cxx Invoking: GCC C++ Compiler g++ -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"mythrow.d" -MT"mythrow.o" -o "mythrow.o" "../mythrow.cxx" Finished building: ../mythrow.cxx Building target: libMyThrow.so Invoking: GCC C++ Linker g++ -shared -o "libMyThrow.so" ./mythrow.o /usr/bin/ld: ./mythrow.o: relocation R_X86_64_PC32 against symbol `_ZTINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE' can not be used when making a shared object; recompile with -fPIC makefile:44: recipe for target 'libMyThrow.so' failed /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status make: *** [libMyThrow.so] Error 1 "make all" terminated with exit code 2. Build might be incomplete. 08:25:54 Build Failed. 4 errors, 0 warnings. (took 1s.917ms) === Eclipse built subdir.mk === === Note that -fPIC is NOT specified on the g++ command for compile === === This flag is always and only required for bulding shared libraries === don@myhost:~$ cat /home/don/CDTWorkspace/MyThrow/Release/subdir.mk ################################################################################ # Automatically-generated file. Do not edit! ################################################################################ # Add inputs and outputs from these tool invocations to the build variables CXX_SRCS += \ ../mythrow.cxx CXX_DEPS += \ ./mythrow.d OBJS += \ ./mythrow.o # Each subdirectory must supply rules for building sources it contributes %.o: ../%.cxx @echo 'Building file: $<' @echo 'Invoking: GCC C++ Compiler' g++ -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' don@myhost:~$ cat CDTeclipse/.eclipseproduct name=Eclipse Platform id=org.eclipse.platform version=4.10.0 === Yes, it is an old version of GCC, but the === === "Position Independent Compilation" flag === === has been, and still is required for building === === shared libraries with GCC. Don't know if Clang === === has similar flag for same reason or not. ==== don@myhost:~$ g++ --version g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. don@myhost:~$ uname -a Linux myhost 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) x86_64 GNU/Linux