CMAKE separate Linker and Compiler Flags - eclipse

Right now my toolchain.cmake looks loke this:
CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-gcc GNU)
SET(CMAKE_ASM_COMPILER arm-none-eabi-as)
SET(CMAKE_OBJCOPY arm-none-eabi-objcopy CACHE INTERNAL "objcopy" FORCE)
SET(CMAKE_OBJDUMP arm-none-eabi-objdump CACHE INTERNAL "objdump" FORCE)
# Compiler Flags
SET(MCU_FLAGS "-mcpu=cortex-m3 -mthumb")
SET(CMAKE_BUILD_FLAGS "-O2 -g -mfpu=vfp -mfloat-abi=soft -Wa,-meabi=5 -ffunction-sections -fno-common -pedantic -Wall -Wextra -Wno-missing-field-initializers")
SET(CMAKE_C_FLAGS "${MCU_FLAGS} ${CMAKE_BUILD_FLAGS}" CACHE INTERNAL "c compiler flags")
SET(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS} CACHE INTERNAL "cxx compiler flags")
SET(CMAKE_ASM_FLAGS "-g -mcpu=cortex-m3 -mthumb -mfpu=vfp -mfloat-abi=soft -meabi=5 -warn" CACHE INTERNAL "asm compiler flags")
SET(CMAKE_EXE_LINKER_FLAGS "-mcpu=cortex-m3 -mthumb -Wall -Wextra -Wno-missing-field-initializers -g -nostartfiles -Wl,-T1.ld,-M=1.map,--gc-sections" CACHE INTERNAL "exe link flags")
The problem is that CMake passes to the Linker additionally the Compiler-flags! Is there any way to separate these two?
Another thing is if I use another compiler-tool-chain (Like Fujitsu Softtune) how can I tell CMake explicitly to take a Linker and not the compiler to Link objects?
Thanks
So i finally solved it. for evryone else with the same problem, i changed CMakelists as follow:
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C CXX ASM)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${LD_FLAGS_STR} -m ${PROJECT_NAME}.map")
set(CMAKE_C_LINK_EXECUTABLE "FLNK907S.EXE -o <TARGET> <LINK_FLAGS> <OBJECTS>")
and it works fine...
where ${LD_FLAGS_STR} is just the list of my linker flags (own variable). and LNK907S.EXE is the name of Linker i 'm using (Fujitsu).

Try using SET_TARGET_PROPERTIES to set the link flags, respectively:
SET(MCU_FLAGS "-mcpu=cortex-m3 -mthumb")
SET(CMAKE_BUILD_FLAGS "-O2 -g -mfpu=vfp -mfloat-abi=soft -Wa,-meabi=5 -ffunction-sections -fno-common -pedantic -Wall -Wextra -Wno-missing-field-initializers")
SET(CMAKE_C_FLAGS "${MCU_FLAGS} ${CMAKE_BUILD_FLAGS}")
SET(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
SET(CMAKE_ASM_FLAGS "-g -mcpu=cortex-m3 -mthumb -mfpu=vfp -mfloat-abi=soft -meabi=5 -warn")
SET_TARGET_PROPERTIES(FOO PROPERTIES LINK_FLAGS "-mcpu=cortex-m3 -mthumb -Wall -Wextra -Wno-missing-field-initializers -g -nostartfiles -Wl,-T1.ld,-M=1.map,--gc-sections")
Here, I have assumed your excutable is called "FOO". Note that the link libaries are specified on a per-target basis. If you need special compiler flags for the target only, you can use COMPILE_FLAGS in SET_TARGET_PROPERTIES as well.

With newer versions of cmake, using generator expressions [1] has been my preferred approach.
target_compile_options(${TARGET_NAME}
PRIVATE
$<$<COMPILE_LANGUAGE:C>:${C_DEFS} ${C_FLAGS}>
$<$<COMPILE_LANGUAGE:ASM>:${ASM_FLAGS}>)
[1] https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html

Related

platformIO does not show binary sizes on build

I am using VsCode with PlatformIO with a very simple program.
It compiles correctly and produces working elf and hex files.
However, unless pio states that it checkes the sizes it does not output anything.
my configuration is the following
[env:release]
platform = atmelavr
board_build.mcu = atmega168A
board_build.f_cpu = 8000000L
running the build it just outputs:
Processing release (platform: atmelavr)
----------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
HARDWARE: ATMEGA168A 8MHz,
PACKAGES:
- toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> [had to replace link to being allowed to post]
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\release\src\HMI.o
Compiling .pio\build\release\src\Oled.o
Compiling .pio\build\release\src\Segment.o
Compiling .pio\build\release\src\main.o
Linking .pio\build\release\firmware.elf
Checking size .pio\build\release\firmware.elf
Building .pio\build\release\firmware.hex
=========================================================== [SUCCESS] Took 1.95 seconds ===========================================================
even with running it with -v it shows not much more information
Processing release (platform: atmelavr; board_build.mcu: atmega168A; board_build.f_cpu: 8000000L)
----------------------------------------------------------------------------------------------------------------------------------------------------HARDWARE: ATMEGA168A 8MHz,
PACKAGES:
- toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> [had to replace link to being allowed to post]
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
avr-gcc -o .pio\build\release\src\HMI.o -c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega168A -DF_CPU=8000000L -DPLATFORMIO=50101 -Isrc src\HMI.c
avr-gcc -o .pio\build\release\src\Oled.o -c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega168A -DF_CPU=8000000L -DPLATFORMIO=50101 -Isrc src\Oled.c
avr-gcc -o .pio\build\release\src\Segment.o -c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega168A
-DF_CPU=8000000L -DPLATFORMIO=50101 -Isrc src\Segment.c
avr-gcc -o .pio\build\release\src\main.o -c -std=gnu11 -fno-fat-lto-objects -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega168A -DF_CPU=8000000L -DPLATFORMIO=50101 -Isrc src\main.c
avr-gcc -o .pio\build\release\firmware.elf -Os -mmcu=atmega168A -Wl,--gc-sections -flto -fuse-linker-plugin .pio\build\release\src\HMI.o .pio\build\release\src\Oled.o .pio\build\release\src\Segment.o .pio\build\release\src\main.o -L.pio\build\release -Wl,--start-group -lm -Wl,--end-group
MethodWrapper(["checkprogsize"], [".pio\build\release\firmware.elf"])
avr-objcopy -O ihex -R .eeprom .pio\build\release\firmware.elf .pio\build\release\firmware.hex
=========================================================== [SUCCESS] Took 1.77 seconds ===========================================================
I am using
PIO extension v2.3.2
PIO Core 5.1.1·Home 3.3.4
platform atmelavr at 3.3.0
Manually calling avr-size from the the downloaded packages correctly shows the info.
Any suggestions how to solve this?
Adding an explicit board config item to the config seems to fix that problem.
[env:release]
platform = atmelavr
board = ATmega168
board_build.mcu = atmega168A
board_build.f_cpu = 8000000L

No such file error in System Workbench for STM32

I get an error saying
fatal error: stm32l0xx_hw_conf.h: No such file or directory
even though I have included stm32l0xx_hw_conf.h in the same project. How do I solve this error?
Edit: The console output for this error is:
Invoking: MCU GCC Compiler
/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Debug
arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft
-DHAL_OK -DSTM32L0 -DSTM32L071xx -DUSE_MIROMICO_FMLR -DUSE_HAL_DRIVER -DUSE_BAND_868 -DSENSOR_ENABLED -DDEBUG -I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/inc"
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy"
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I/home/dinesh/fmlr_bitbucket/lorawan/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc"
-I../../../../../../../../Drivers/CMSIS/Device/ST/STM32L1xx/Include -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/CMSIS/Device/ST/STM32L0xx/Include"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/FMLR" -I../../../../../../../../Drivers/STM32L1xx_HAL_Driver/Inc -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/STM32L0xx_HAL_Driver/Inc"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/CMSIS/Include" -I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Crypto"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Mac"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Phy"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Utilities"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/Common" -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/sts_sht_21"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/bmp280" -I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Core"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/sx1272mb2das" -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/sx1272mb2das/Phy" -Og -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fmessage-length=0 -MMD -MP -MF"Projects/MultiSensorHub/src/debug.d" -MT"Projects/MultiSensorHub/src/debug.o" -o "Projects/MultiSensorHub/src/debug.o"
"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/src/debug.c"
/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Debug
arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft
-DHAL_OK -DSTM32L0 -DSTM32L071xx -DUSE_MIROMICO_FMLR -DUSE_HAL_DRIVER -DUSE_BAND_868 -DSENSOR_ENABLED -DDEBUG -I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/inc"
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy"
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I/home/dinesh/fmlr_bitbucket/lorawan/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc"
-I../../../../../../../../Drivers/CMSIS/Device/ST/STM32L1xx/Include -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/CMSIS/Device/ST/STM32L0xx/Include"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/FMLR" -I../../../../../../../../Drivers/STM32L1xx_HAL_Driver/Inc -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/STM32L0xx_HAL_Driver/Inc"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/CMSIS/Include" -I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Crypto"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Mac"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Phy"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Utilities"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/Common" -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/sts_sht_21"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/bmp280" -I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Core"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/sx1272mb2das" -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/sx1272mb2das/Phy" -Og -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fmessage-length=0 -MMD -MP -MF"Projects/MultiSensorHub/src/hw_gpio.d" -MT"Projects/MultiSensorHub/src/hw_gpio.o" -o "Projects/MultiSensorHub/src/hw_gpio.o"
"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/src/hw_gpio.c"
/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Debug
arm-none-eabi-gcc -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft
-DHAL_OK -DSTM32L0 -DSTM32L071xx -DUSE_MIROMICO_FMLR -DUSE_HAL_DRIVER -DUSE_BAND_868 -DSENSOR_ENABLED -DDEBUG -I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/inc"
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy"
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc
-I/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I/home/dinesh/fmlr_bitbucket/lorawan/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc/Legacy"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/SW4STM32/Miromico-FMLR/Drivers/STM32L0xx_HAL_Driver/Inc"
-I../../../../../../../../Drivers/CMSIS/Device/ST/STM32L1xx/Include -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/CMSIS/Device/ST/STM32L0xx/Include"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/FMLR" -I../../../../../../../../Drivers/STM32L1xx_HAL_Driver/Inc -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/STM32L0xx_HAL_Driver/Inc"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/CMSIS/Include" -I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Crypto"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Mac"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Phy"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Utilities"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/Common" -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/sts_sht_21"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/Components/bmp280" -I"/home/dinesh/fmlr_bitbucket/lorawan/Middlewares/Third_Party/Lora/Core"
-I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/sx1272mb2das" -I"/home/dinesh/fmlr_bitbucket/lorawan/Drivers/BSP/sx1272mb2das/Phy" -Og -g3 -Wall -fmessage-length=0 -ffunction-sections -c -fmessage-length=0 -MMD -MP -MF"Projects/MultiSensorHub/src/bsp.d" -MT"Projects/MultiSensorHub/src/bsp.o" -o "Projects/MultiSensorHub/src/bsp.o"
"/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/src/bsp.c"
In file included from
/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/inc/hw.h:72:0,from
/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/src/bsp.c:50:
/home/dinesh/fmlr_bitbucket/lorawan/Projects/Multi/Applications/LoRa/MultiSensorHub/inc/hw_conf.h:123:10:
fatal error: stm32l0xx_hw_conf.h: No such file or directory #include
"stm32l0xx_hw_conf.h"
You need to set the path to the include file in the project setting (if its a managed project) or the makefile if it is not. Adding a file to the project does not add it to the include path.
It is possible you need to re-index the project. In Eclipse, you can right click the project and select Index->Rebuild.

How to recompile libperl.a object files with -fPIC flag?

This question arose when trying to fix some installation problems
with QtCore4. At some point make tried to run the following command:
/usr/bin/c++ -fPIC -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong \
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -DNDEBUG \
-shared -Wl,-soname,QtCore4.so -o ../../blib/arch/auto/QtCore4/QtCore4.so \
CMakeFiles/perlqtcore4.dir/binding.cpp.o \
CMakeFiles/perlqtcore4.dir/handlers.cpp.o \
CMakeFiles/perlqtcore4.dir/marshall_types.cpp.o \
CMakeFiles/perlqtcore4.dir/util.cpp.o \
CMakeFiles/perlqtcore4.dir/QtCore4.c.o \
-lQtCore -lQtGui -lQtNetwork \
/home/hakon/perlbrew/perls/perl-5.24.1/lib/5.24.1/x86_64-linux/CORE/libperl.a \
../../smokeqt/qtgui/libsmokeqtgui.so.3.0.0 \
../../smokeqt/qtnetwork/libsmokeqtnetwork.so.3.0.0 \
-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc -lQtGui -lQtNetwork \
../../smokeqt/qtcore/libsmokeqtcore.so.3.0.0 -lQtCore \
../../smokegen/bin/libsmokebase.so.3.0.0 \
-Wl,-rpath,/home/hakon/Qt4-0.99.0/smokeqt/qtgui:/home/hakon/Qt4-0.99.0/smokeqt/qtnetwork:/home/hakon/Qt4-0.99.0/smokeqt/qtcore:/home/hakon/Qt4-0.99.0/smokegen/bin:
which failed with the following error message from the linker:
/usr/bin/ld: /home/hakon/perlbrew/perls/perl-5.24.1/lib/5.24.1/x86_64-linux/CORE/libperl.a(toke.o):
relocation R_X86_64_PC32 against symbol `PL_curcop' can not be used when making
a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
From the error message, it seems to me that the object files (here: toke.o) in
libperl.a was compiled without the -fPIC flag set.
The questions I have now are:
How can I recompile the object files in libperl.a with -fPIC ?
Could this recompilation cause other problems not related to
QtCore4 (since it is likely that libperl.a will be used (linked
with) by other applications/programs not related to QtCore4)?
I am using Ubuntu 16.10 and perl version 5.24.1.
How can I recompile the object files in libperl.a with -fPIC
By recompiling libperl.a with the -fPIC flag.
./Configure -des -Accflags=-fPIC ...
Could this recompilation cause other problems not related to QtCore4 (since it is likely that libperl.a will be used (linked with) by other applications/programs not related to QtCore4)?
Yes. Prefer a shared libperl. -Duseshrplib
Which is required when embedding perl into shared libs. You can do away with the -fPIC trick which is required on ELF, but a shared libperl makes it much easier.

Meaning of the g++ flags "-Wall", " -W", and "-Werror"

What are these and what do they do?
-Wall
-W
-Werror
I am using the terminal in Ubuntu to compile programs with this command:
g++ -Wall -W -Werror main.cpp -o exec
What is the explanation?
-Wall: enable a set of warning, but actually not all.
-W: enable extra warnings. It's advised to use -Wextra instead which has the same meaning
-Werror: every warning is treated as an error.
See GCC documentation:
3.8 Options to Request or Suppress Warnings

Mex compiling on 64 bit linux - /usr/bin/ld: cannot find -lstdc++

Okay I am trying to compile a mex file on 64 bit linux, ubuntu to be precise with Matlab 2013a.
First it gave a error that it could not find GLIBCXX_3.4.15. Which was not part of the
/usr/local/MATLAB/R2013a/sys/os/glnxa64/libstdc++.so.6. I found this thread /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found and succesfully created a symbolic link ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17 libstdc++.so.6 in /usr/local/MATLAB/R2013a/sys/os/glnxa64
Now I tried to compile again and now I get /usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
This is the output
>> mex -v tload3.c
**************************************************************************
Warning: Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require
the use of -largeArrayDims and remove the -compatibleArrayDims
option. For more information, see:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html
**************************************************************************
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /home/wouter/.matlab/R2013a/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /usr/local/MATLAB/R2013a
-> CC = gcc
-> CC flags:
CFLAGS = -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread
CDEBUGFLAGS = -g
COPTIMFLAGS = -O -DNDEBUG
CLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = g++
-> CXX flags:
CXXFLAGS = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O -DNDEBUG
CXXLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm
arguments = -DMX_COMPAT_32
-> LD = gcc
-> Link flags:
LDFLAGS = -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2013a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexa64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
Warning: You are using gcc version "4.7.3". The version
currently supported with MEX is "4.4.x".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
-> gcc -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "tload3.c"
-> gcc -O -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2013a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o "tload3.mexa64" tload3.o -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
mex: link of ' "tload3.mexa64"' failed.
Error using mex (line 206)
Unable to complete successfully.
ps there is a another thread with about the same title, Error building MEX-files (MATLAB 2012a) on Kubuntu '/usr/bin/ld: cannot find -lstdc++', unfortunatly the answer, installing sudo apt-get install libstdc++6-4.4-dev did not work for me.
Same problem here on Ubuntu 13.04 using MATLAB 2013a.
I solved it doing:
sudo mv /usr/local/MATLAB/R2013a/sys/os/glnxa64/libstdc++.so.6 /usr/local/MATLAB/R2013a/sys/os/glnxa64/libstdc++.so.6.old
To keep a backup just in case.
And then a symbolic link:
sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17 /usr/local/MATLAB/R2013a/sys/os/glnxa64/libstdc++.so.6
I had the same problem and this worked for me
Navigate to the following path cd /usr/local/MATLAB/R2013a/sys/os/glnxa64/, (your path might varies) then remove the libstdc library (or safer rename it)
sudo mv libstdc++.so.6 libstdc++.so.6.old
I have the same configuration, Ubuntu Linux 64 bit with Matlab 2013a
Look at this line gcc -O -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2013a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -o "tload3.mexa64" tload3.o -Wl,-rpath-link,/usr/local/MATLAB/R2013a/bin/glnxa64 -L/usr/local/MATLAB/R2013a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++.
The options with L are the places where gcc/the linker looks for libraries. Id sugest trying to put the symlink in /usr/local/MATLAB/R2013a/bin/glnxa64 ( libstdc++.so.6 is there in 2012a), and start matlab from a terminal, it spits some errors there. Or add the new folder as a CLIB argument.
And I also would delete the -ansi part for c ( replace it with -std=c99), so that it won't give you errors on using \ style comments in your c code.
You created the link libstdc++.so.6 in /usr/local/MATLAB/R2013a/bin/glnxa64 to the library in your system, installed by apt-get install libstdc++6-4.4-dev .
Now try creating also a link named libstdc++.so to libstdc++.so.6 in
/usr/local/MATLAB/R2013a/bin/glnxa64.
I had the same problem and none of the posted solutions worked for me (i.e. deleting or adding new symlinks), and it turned out that I hadn't installed the appropriate compiler package!
For me, the solution was:
sudo yum install gcc-g++
I'm running MATLAB 2014b on 64-bit Linux (RHEL 6).