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.
Related
When I install B::C with cpanm, it hangs
$ sudo cpanm B::C
--> Working on B::C
Fetching http://www.cpan.org/authors/id/R/RU/RURBAN/B-C-1.57.tar.gz ... OK
Configuring B-C-1.57 ... OK
Building and testing B-C-1.57 ... ^C
First you'll want to try to check the install by using the verbose flag cpanm -v B::C, after which you should see a lot of looping like
x86_64-linux-gnu-gcc -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/x86_64-linux-gnu/perl/5.28/CORE -o cccode1_o1 cccode1_o1.c -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.28/CORE -lperl -ldl -lm -lpthread -lc -lcrypt 2>/dev/null 2>&1
# /usr/bin/ld: cannot find -lperl
collect2: error: ld returned 1 exit status
This is because ld can't find libperl.so. If you're on Debian you'll need to run,
sudo apt install libperl-dev
I’m using the Random Forest library for Matlab (link). I’m using it for classification. On Windows it works very well out of the box (precombiled mex files) but I also want to run it on a CentOS cluster.
I have tried to compile it on the cluster by executing make mex but I’m getting an error. The output is as follows:
rm twonorm_test -rf
rm tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
echo 'Compiling classTree.cpp'
Compiling classTree.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/classTree.cpp -o tempbuild/classTree.o
echo 'Compiling Cokus (random number generator)'
Compiling Cokus (random number generator)
g++ -fpic -O2 -funroll-loops -msse3 -c src/cokus.cpp -o tempbuild/cokus.o
echo 'Compiling rfsub.f (fortran subroutines)'
Compiling rfsub.f (fortran subroutines)
gfortran -O2 -fpic -c src/rfsub.f -o rfsub.o
echo 'Compiling rfutils.cpp'
Compiling rfutils.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/rfutils.cpp -o tempbuild/rfutils.o
echo 'Generating Mex'
Generating Mex
mex src/mex_ClassificationRF_train.cpp src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o tempbuild/cokus.o -o mexClassRF_train -lgfortran -lm -DMATLAB -g
Unknown MEX argument '-o'.
make: *** [mex_classRF] Error 255
Does somebody knows how to solve this issue? If you want, you can take RF_MexStandalone-v0.02.zip from the above link and then go to randomforest-matlab/RF_Reg_C/Makefile.
Edit: I have change -o to -output but now the output is the following:
rm twonorm_test -rf
rm tempbuild/*.o *.o -rf
rm *~ -rf
rm *.mexw32 twonorm_test -rf
rm *.mexa64 -rf
rm classRF -rf
rm *.exe -rf
echo 'Compiling classTree.cpp'
Compiling classTree.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/classTree.cpp -o tempbuild/classTree.o
echo 'Compiling Cokus (random number generator)'
Compiling Cokus (random number generator)
g++ -fpic -O2 -funroll-loops -msse3 -c src/cokus.cpp -o tempbuild/cokus.o
echo 'Compiling rfsub.f (fortran subroutines)'
Compiling rfsub.f (fortran subroutines)
gfortran -O2 -fpic -c src/rfsub.f -o rfsub.o
echo 'Compiling rfutils.cpp'
Compiling rfutils.cpp
g++ -fpic -O2 -funroll-loops -msse3 -c src/rfutils.cpp -o tempbuild/rfutils.o
echo 'Generating Mex'
Generating Mex
mex src/mex_ClassificationRF_train.cpp src/classRF.cpp tempbuild/classTree.o tempbuild/rfutils.o rfsub.o tempbuild/cokus.o -output mexClassRF_train -lgfortran -lm -DMATLAB -g
Building with 'g++'.
cc1plus: error: unrecognized command line option "-std=c++11"
make: *** [mex_classRF] Error 255
I did not find an option -std=c++11 in the makefile.
The error is quite self-explanatory: the option -o is not recognized. If you type mex -help you see the options mex accepts. Try to replace -o with -output.
EDIT regarding the std=c++11 option, you are probably using an old version of gcc compiler. You can either change it to std=c++0x which is the equivalent option (but note that some features of the c++11 standard may not be present\implemented), or upgrade to an up-to-date version of gcc.
If you need more help, please report the output of g++ --version.
i tried installing the perl module XML::LibXSLT but it fails. googled for it for hours now but nothing help so i am posting this. Maybe someone can help!
Thanks in advance!
cpan XML::LibXSLT
CPAN: Storable loaded ok (v2.20)
Going to read '/root/.cpan/Metadata'
Database was generated on Mon, 28 Oct 2013 11:08:37 GMT
Running install for module 'XML::LibXSLT'
CPAN: YAML loaded ok (v0.84)
Running make for S/SH/SHLOMIF/XML-LibXSLT-1.81.tar.gz
CPAN: Digest::SHA loaded ok (v5.47)
CPAN: Compress::Zlib loaded ok (v2.062)
Checksum for /root/.cpan/sources/authors/id/S/SH/SHLOMIF/XML-LibXSLT-1.81.tar.gz ok
CPAN: Archive::Tar loaded ok (v1.58)
XML-LibXSLT-1.81/
XML-LibXSLT-1.81/perl-libxml-mm.h
XML-LibXSLT-1.81/benchmark/
XML-LibXSLT-1.81/benchmark/Driver/
XML-LibXSLT-1.81/benchmark/Driver/Sablotron.pm
XML-LibXSLT-1.81/benchmark/Driver/LibXSLT.pm
XML-LibXSLT-1.81/benchmark/Driver/BaseClass.pm
XML-LibXSLT-1.81/benchmark/benchmark.pl
XML-LibXSLT-1.81/Changes
XML-LibXSLT-1.81/LibXSLT.pm
XML-LibXSLT-1.81/MANIFEST
XML-LibXSLT-1.81/testcases/
XML-LibXSLT-1.81/testcases/default.conf
XML-LibXSLT-1.81/example/
XML-LibXSLT-1.81/example/fatal.xsl
XML-LibXSLT-1.81/example/2.xml
XML-LibXSLT-1.81/example/bad3.xsl
XML-LibXSLT-1.81/example/nonfatal.xsl
XML-LibXSLT-1.81/example/1.xml
XML-LibXSLT-1.81/example/bad2.xsl
XML-LibXSLT-1.81/example/1.xsl
XML-LibXSLT-1.81/example/2.xsl
XML-LibXSLT-1.81/example/bad1.xsl
XML-LibXSLT-1.81/Makefile.PL
XML-LibXSLT-1.81/META.yml
XML-LibXSLT-1.81/META.json
XML-LibXSLT-1.81/README
XML-LibXSLT-1.81/t/
XML-LibXSLT-1.81/t/04params.t
XML-LibXSLT-1.81/t/rt71345_a.t
XML-LibXSLT-1.81/t/09exslt.t
XML-LibXSLT-1.81/t/06output.t
XML-LibXSLT-1.81/t/03input.t
XML-LibXSLT-1.81/t/08literal.t
XML-LibXSLT-1.81/t/02dromeds.t
XML-LibXSLT-1.81/t/06entities.t
XML-LibXSLT-1.81/t/11utf8.t
XML-LibXSLT-1.81/t/10functions.t
XML-LibXSLT-1.81/t/05quick.t
XML-LibXSLT-1.81/t/07blankdoc.t
XML-LibXSLT-1.81/t/13error.t
XML-LibXSLT-1.81/t/01basic.t
XML-LibXSLT-1.81/t/14security.t
XML-LibXSLT-1.81/t/12import.t
XML-LibXSLT-1.81/t/15misc.t
XML-LibXSLT-1.81/t/rt71345_b.t
XML-LibXSLT-1.81/typemap
XML-LibXSLT-1.81/LibXSLT.xs
XML-LibXSLT-1.81/ppport.h
XML-LibXSLT-1.81/perl-libxml-mm.c
CPAN: File::Temp loaded ok (v0.22)
CPAN.pm: Going to build S/SH/SHLOMIF/XML-LibXSLT-1.81.tar.gz
running xslt-config... failed
using fallback values for LIBS and INC
options:
LIBS='-L/usr/local/lib -L/usr/lib -lxslt -lxml2 -lz -lm'
INC='-I/usr/local/include -I/usr/include'
If this is wrong, Re-run as:
$ /usr/bin/perl Makefile.PL LIBS='-L/path/to/lib' INC='-I/path/to/include'
looking for -lxslt... yes
looking for -lexslt... yes
running pkg-config libexslt... ok
Checking if your kit is complete...
Looks good
Generating a GNU-style Makefile
Writing Makefile for XML::LibXSLT
Writing MYMETA.yml and MYMETA.json
cp LibXSLT.pm blib/lib/XML/LibXSLT.pm
/usr/bin/perl /usr/share/perl5/ExtUtils/xsubpp -typemap /usr/share/perl5/ExtUtils/typemap -typemap typemap LibXSLT.xs > LibXSLT.xsc && mv LibXSLT.xsc LibXSLT.c
gcc -c -I/usr/local/include -I/usr/include -I/usr/include/libxml2 -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DVERSION=\"1.81\" -DXS_VERSION=\"1.81\" -fPIC "-I/usr/lib64/perl5/CORE" -DHAVE_BLANK -DHAVE_BLANK -DHAVE_EXSLT LibXSLT.c
LibXSLT.xs: In function ‘LibXSLT__function’:
LibXSLT.xs:252: warning: pointer targets in passing argument 1 of ‘xmlNewDoc’ differ in signedness
/usr/include/libxml2/libxml/tree.h:735: note: expected ‘const xmlChar *’ but argument is of type ‘char *’
LibXSLT.xs: In function ‘LibXSLT_context_element’:
LibXSLT.xs:518: warning: unused variable ‘ent’
LibXSLT.xs: In function ‘LibXSLT_init_functions’:
LibXSLT.xs:916: warning: suggest parentheses around assignment used as truth value
LibXSLT.xs: In function ‘LibXSLT_init_elements’:
LibXSLT.xs:948: warning: suggest parentheses around assignment used as truth value
gcc -c -I/usr/local/include -I/usr/include -I/usr/include/libxml2 -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DVERSION=\"1.81\" -DXS_VERSION=\"1.81\" -fPIC "-I/usr/lib64/perl5/CORE" -DHAVE_BLANK -DHAVE_BLANK -DHAVE_EXSLT perl-libxml-mm.c
rm -f blib/arch/auto/XML/LibXSLT/LibXSLT.so
LD_RUN_PATH="/usr/lib64:/lib64" gcc -shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic LibXSLT.o perl-libxml-mm.o -o blib/arch/auto/XML/LibXSLT/LibXSLT.so \
-L/usr/local/lib -L/usr/lib -lxslt -lxml2 -lz -lm -lexslt -lgcrypt -ldl -lgpg-error -lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc \
/usr/bin/ld: cannot find -lgdbm
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/XML/LibXSLT/LibXSLT.so] Error 1
SHLOMIF/XML-LibXSLT-1.81.tar.gz
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
'
Any help is highly appreciated!
The error is /usr/bin/ld: cannot find -lgdbm. do you find gdbm library on your system?
run:
# updatedb
# locate gdbm
The output of locate command should list libgdbm.so. If it is not then try installing the same using your Distro's package manager:
Here is output on my ubuntu:
# locate gdbm
/usr/lib/libgdbm.so.3
/usr/lib/libgdbm.so.3.0.0
/usr/lib/libgdbm_compat.so.3
/usr/lib/libgdbm_compat.so.3.0.0
and here is the output from my RHEL 6.4:
# locate gdbm
/usr/lib64/libgdbm.so.2
/usr/lib64/libgdbm.so.2.0.0
To install gdbm, run these commands:
on ubuntu: apt-get install libgdbm3
On centos/RHEL: yum install gdbm
hope this helps.
/usr/bin/ld: cannot find -lgdbm
Looks like you don't have the gdbm library installed. I can't see which Linux (or, perhaps, Unix) distribution you're using, but gdbm is almost certainly per-packaged for it, so you just need to work out what the package is called and use apt or yum (or whatever is appropriate) to install it.
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).
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