I need to implement an authentication scheme on an embedded device and require gmp in order to perform large integer operations.
After downloading the sources they must be compiled with a proprietary version of compile tools in order to be able to statically link libraries(only one binary can be uploaded onto the controller at a time).
After running configure the following make file is produced.
Running make with the proprietary compiler
make CC=/home/TI/ccsv5/tools/compiler/gcc-arm-none-eabi-4_7-2012q4/arm-none-eabi/bin/gcc
gives the following errors:
make[2]: Entering directory `/home/TI_workspace/gmp-6.0.0/mpn'
/bin/bash ../libtool --tag=CC --mode=compile /home/TI/ccsv5/tools/compiler/gcc-arm-none-eabi-4_7-2012q4/arm-none-eabi/bin/gcc -DHAVE_CONFIG_H -I. -I.. -D__GMP_WITHIN_GMP -I.. -DOPERATION_`echo fib_table | sed 's/_$//'` -O2 -pedantic -fomit-frame-pointer -c -o fib_table.lo fib_table.c
libtool: compile: /home/TI/ccsv5/tools/compiler/gcc-arm-none-eabi-4_7-2012q4/arm-none-eabi/bin/gcc -DHAVE_CONFIG_H -I. -I.. -D__GMP_WITHIN_GMP -I.. -DOPERATION_fib_table -O2 -pedantic -fomit-frame-pointer -c fib_table.c -fPIC -DPIC -o .libs/fib_table.o
gcc: error trying to exec 'cc1': execvp: No such file or directory
make[2]: *** [fib_table.lo] Error 1
make[2]: Leaving directory `/home/TI_workspace/gmp-6.0.0/mpn'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/TI_workspace/gmp-6.0.0'
make: *** [all] Error 2
cc1 is located in:
$ sudo find . -name cc1 -print
./ccsv5/tools/compiler/gcc-arm-none-eabi-4_7-2012q4/lib/gcc/arm-none-eabi/4.7.3/cc1
Is it possible to generate a makefile so that it uses the proprietary tool chain instead of the default one? If yes, how should it be configured?
Edit:
Bellow are the ./configure options:
$ ./configure --help
`configure' configures GNU MP 6.0.0 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
For better control, use the options below.
Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/gmp]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-maintainer-mode enable make rules and dependencies not useful
(and sometimes confusing) to the casual installer
--enable-assert enable ASSERT checking [[default=no]]
--enable-alloca how to get temp memory [[default=reentrant]]
--enable-cxx enable C++ support [[default=no]]
--enable-assembly enable the use of assembly loops [[default=yes]]
--enable-fft enable FFTs for multiplication [[default=yes]]
--enable-old-fft-full enable old mpn_mul_fft_full for multiplication
[[default=no]]
--enable-nails use nails on limbs [[default=no]]
--enable-profiling build with profiler support [[default=no]]
--enable-fat build a fat binary on systems that support it
[[default=no]]
--enable-minithres choose minimal thresholds for testing [[default=no]]
--enable-fake-cpuid enable GMP_CPU_TYPE faking cpuid [[default=no]]
--enable-shared[=PKGS] build shared libraries [default=yes]
--enable-static[=PKGS] build static libraries [default=yes]
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-readline readline support in calc demo program
[[default=detect]]
--with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
both]
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-sysroot=DIR Search for dependent libraries within DIR
(or the compiler's sysroot if not specified).
Some influential environment variables:
ABI desired ABI (for processors supporting more than one ABI)
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
CC_FOR_BUILD
build system C compiler
CPP_FOR_BUILD
build system C preprocessor
CXX C++ compiler command
CXXFLAGS C++ compiler flags
CXXCPP C++ preprocessor
M4 m4 macro processor
YACC The `Yet Another Compiler Compiler' implementation to use.
Defaults to the first program found out of: `bison -y', `byacc',
`yacc'.
YFLAGS The list of arguments that will be passed by default to $YACC.
This script will default YFLAGS to the empty string to avoid a
default value of `-d' given by some make applications.
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Related
I started to learn APUE* and compile the source code
Download the source code from Source Code
Extract it to
$ pwd
/Users/me/Desktop/PubRepo/C/APUE/apue.3e
Read readme
$ cat readme
Read the file called DISCLAIMER.
On Freebsd, type "gmake".
On other platforms, type "make" (as long as this is gnu make).
For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com.
Please direct questions, suggestions, and bug reports to sar#apuebook.com.
Steve Rago
January 2013
I checked make version
$ make --version
GNU Make 3.81
Copyright (C) 2006 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.
This program built for i386-apple-darwin11.3.0
make but report error:
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE -c -o sleep.o sleep.c
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
make[1]: *** [getcputc] Error 254
make: *** [all] Error 1
I searched and found answer to add cp ./lib/error.c /usr/local/include/
$ cp ./lib/error.c /usr/local/include/
make clean and make
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [getcputc] Error 1
make: *** [all] Error 1
The error is still there.
How could I apply apue.h?
* W Richard Stevens, Stephen A Rago
Advanced Programming in the Unix Environment, 3rd Edn, 2013.
I downloaded the APUE source to a Mac running macOS 10.14.1 Mojave with XCode 10.1 installed (see also Can't compile a C program on a Mac after upgrade to Mojave).
I then ran make CC=/usr/bin/clang (using /usr/bin/gcc is also OK) to use that instead of a home-built GCC 8.2.0, which failed in the db subdirectory. If you don't have any non-standard version of GCC installed on your PATH ahead of /usr/bin/gcc or /usr/bin/clang, you shouldn't need the CC=… argument.
This did a lot of building — all of it successfully (once I'd specified the compiler explicitly; I got an error on the -R. argument with the home-built GCC).
Make sure you have XCode properly installed. Worry about the Command Line Tools — see the "Can't compile" question for information on where to get them. You shouldn't need /usr/include for this, but it is likely to make life easier; again, see the "Can't compiler" question for how to install /usr/include.
There is an answer here from #makhlaghi that helped me a long time ago.
https://unix.stackexchange.com/questions/105483/compiling-code-from-apue.
Here is the answer that worked for me:
A short review of how to write and compile the programs in Advanced Programming in the UNIX® Environment, thanks to slm for helping me understand the steps. You can download the source code from here. I wish this information was included as part of appendix b of the book, where the header file is explained.
The uncompressed file contains directories with the names of the chapters and two others named include and lib. The ones with the names of the chapters have all the programs of that chapter in them.
The include directory contains the header file that is used in most of the programs in the book: apue.h. The lib directory has the source code of the implementations for the that header.
Lets assume the uncompressed file is located at: SCADDRESS/, for example it might be: /home/yourid/Downloads/apue.3e/
Once you uncompress the source code, go in the directory and run make:
$ cd SCADDRESS
$ make
make will compile all the programs in all the chapters. But the important thing is that before that, it will make the library that will contain the implementations of the functions in apue.h.
To compile an example program that you write from the book, run this GCC command (assuming your program's name is myls.c which is the first in the book):
gcc -o myls myls.c -I SCADDRESS/include/ -L SCADDRESS/lib/ -lapue
-I tells gcc which directory to look for the include file. -L tells it the location of the library directory, and -lapue, tells the name of the library file to look for in that directory. Such that -LXXX means to look for a file in the library directory with the name: libXXX.a or libXXX.so.
I'm currently trying to get a toolchain setup so I can build an AVR project from CLion.
My starting point is this, specifically, the Blink example. The issue is that it, along with existing CMake for AVR examples, are all for Linux based systems.
What I've tried is installing WinAVR to get the executables. I've modified the CMakeList.txt so the program names contain the following:
set(AVRCPP "C:/WinAVR-20100110/bin/avr-g++")
set(AVRC "C:/WinAVR-20100110/bin/avr-gcc")
set(AVRSTRIP "C:/WinAVR-20100110/bin/avr-strip")
set(OBJCOPY "C:/WinAVR-20100110/bin/avr-objcopy")
set(OBJDUMP "C:/WinAVR-20100110/bin/avr-objdump")
set(AVRSIZE "C:/WinAVR-20100110/bin/avr-size")
set(AVRDUDE "C:/WinAVR-20100110/bin/avrdude")
set(AVRAS "C:/WinAVR-20100110/bin/avr-as")
While using the Cygwin environment, CMake has no issue finding my compilers, but when I try to build the project, avr-gcc is being passed parameters in Linux format.
C:/WinAVR-20100110/bin/avr-gcc.exe -o CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj -c /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c
avr-gcc.exe: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c: No such file or directory
Is there a way to have CMake pass avr-gcc arguments in a format it can work with?
For reference, this is the full output:
Error:The C compiler "C:/WinAVR-20100110/bin/avr-gcc" is not able to compile a simple test program.
It fails with the following output:
Change Dir: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make.exe "cmTryCompileExec420260872/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec420260872.dir/build.make CMakeFiles/cmTryCompileExec420260872.dir/build
make[1]: Entering directory '/cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp'
/usr/bin/cmake.exe -E cmake_progress_report /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj
C:/WinAVR-20100110/bin/avr-gcc.exe -o CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj -c /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c
avr-gcc.exe: /cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp/testCCompiler.c: No such file or directory
avr-gcc.exe: no input files
CMakeFiles/cmTryCompileExec420260872.dir/build.make:60: recipe for target 'CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj' failed
make[1]: Leaving directory '/cygdrive/c/Users/Daniel/.clion10/system/cmake/generated/2eb381d5/2eb381d5/__default__/CMakeFiles/CMakeTmp'
make[1]: *** [CMakeFiles/cmTryCompileExec420260872.dir/testCCompiler.c.obj] Error 1
Makefile:117: recipe for target 'cmTryCompileExec420260872/fast' failed
make: *** [cmTryCompileExec420260872/fast] Error 2
CMake will not be able to correctly generate this project.
I use cmake and avr on windows and on linux.
The syntax is the same. Why do you want to use cygwin in the mid of that?
In any case you didn't show your toolchain file.
When cross compiling using cmake you need to provide a toolchain file where you set all the configuration related to the compiler.
You need to do this because when cmake starts it try to compile a simple program and it try to run it. If you are using an avr compiler on a computer cmake can't run the executable, so it fails.
You need to put an extra care including this command in the toolchain:
SET(CMAKE_SYSTEM_NAME Generic)
it is needed for skip this compilation and so to avoid the failure.
I think this is a good read where to begin:
http://playground.arduino.cc/Code/CmakeBuild
I am having trouble cross-compiling a library for my arm board using autconf.
I am using this line:
./configure --target=arm-linux --host=arm-linux --prefix=/bla/bla/bla/linux_arm_tool CFLAGS='-m32'
make
make install
When I do file to check it I get:
libjpeg.so.8.4.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped
That doesn't seem right at all, but I tried using it anyway... and I get:
/usr/lib/gcc/arm-linux-gnueabi/4.5.3/../../../../arm-linux-gnueabi/bin/ld: skipping incompatible /bla/bla/bla/bla/../linux_arm_tool/lib/libjpeg.so when searching for -ljpeg
I'm at a loss, I've been googling for an hour now...
So I knew I've cross compiled before using really basic method calls and I figured out why I've gotten away with this before after examining the output:
checking for arm-linux-gnueabi-gcc... no
checking for gcc... gcc
...
...
checking for arm-linux-gnueabi-gcc... gcc
In my /usr/bin there was no arm-linux-gnueabi-gcc, I had to:
ln -s /usr/bin/arm-linux-gnueabi-gcc-4.5 /usr/bin/arm-linux-gnueabi-gcc
I successfully cross-compiled using:
./configure --host=arm-linux-gnueabi -prefix=${CSTOOL_DIR}/linux_arm_tool
as for linking ... I still have to check some things, but I am going to assume I might need to throw some -rpath-link flags in more advanced compiles.
I think the problem could be restated more generally as: "How do I use Autoconf to cross compile for ARM?"
According to ./configure -h:
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
The official GNU documentation is helpful for answering this question:
http://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Hosts-and-Cross_002dCompilation.html
Note when they defining the usage of --host and and --build:
Therefore, whenever you specify --host, be sure to specify --build too.
And here is an example that I just used to configure iperf for my embedded ARM platform:
First of all the "./configure" script is actually called "Autoconf" which really helps for google-ing.
The idea here is to:
Have your cross compilers in your current $PATH
Set the CC and CXX environment variables to point to the cross compilers
Give the right --host and --build
buildpath <--- my little script to setup my $PATH
export CC=arm_v5t_le-gcc
export CXX=arm_v5t_le-g++
./configure --host=armv5tl-montavista-linux-gnueabi --build=x86_64-linux-gnu
You need to override the environment variables CC, LD, and other pertinent ones. Setting those switches doesn't tell configure where your cross tool chain is (it could be anywhere)
Check out some guides for various projects, for instance:
http://wiki.wxwidgets.org/Cross-Compiling_Under_Linux
Also, here is a script I made to setup cross compile for node.js - same idea:
https://gist.github.com/edhemphill/5094239
The libjpeg is not going to work b/c it's a x86 binary, you need it to say:
ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, not stripped
or similar.
This is the reason you are getting a skipping incompatible
# Install arm-linux-gnueabi packages
apt-get install libc6-armel-cross libc6-dev-armel-cross \
binutils-arm-linux-gnueabi arm-linux-gnueabi-gcc libncurses5-dev
./configure --target=arm-linux-gnueabi --host=arm-linux-gnueabi
...
checking for arm-linux-gnueabi-gcc... arm-linux-gnueabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-linux-gnueabi-gcc accepts -g... yes
checking for arm-linux-gnueabi-gcc option to accept ISO C89... none needed
checking whether arm-linux-gnueabi-gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of arm-linux-gnueabi-gcc... gcc3
...
make
arm-linux-gnueabi-gcc -DPACKAGE_NAME=\"Tutorial\ Program\" -DPACKAGE_TARNAME=\"tutorial-program\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"Tutorial\ Program\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"tutorial-program\" -DVERSION=\"1.0\" -I. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
compilation options for cmake (on windows) for ARM target system but when I run configure it's starting compiler tests:
CMake Error at D:/Program Files/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "D:/Program Files/yagarto/bin/arm-none-eabi-gcc.exe" is not
able to compile a simple test program.
It fails with the following output:
Change Dir: D:/merge/complex/build/CMakeFiles/CMakeTmp
Run Build Command:D:/PROGRA~1/YAGART~1/bin/make.exe "cmTryCompileExec/fast"
D:/PROGRA~1/YAGART~1/bin/make.exe -f
CMakeFiles/cmTryCompileExec.dir/build.make
CMakeFiles/cmTryCompileExec.dir/build
make.exe[1]: Entering directory
`D:/merge/complex/build/CMakeFiles/CMakeTmp'
"D:/Program Files/CMake 2.8/bin/cmake.exe" -E cmake_progress_report
D:/merge/complex/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o
"D:/Program Files/yagarto/bin/arm-none-eabi-gcc.exe" -o
CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c
D:/merge/complex/build/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTryCompileExec
"D:/Program Files/yagarto/bin/arm-none-eabi-gcc.exe"
"CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o" -o cmTryCompileExec
-rdynamic
arm-none-eabi-gcc.exe: error: unrecognized option '-rdynamic'
make.exe[1]: *** [cmTryCompileExec] Error 1
Using Yagatdo 4.6.* cross-compilation toolchain
How can I skip this tests or fix -rdynamic error that I am getting?
You can set CMAKE_<LANG>_COMPILER_WORKS to true to suppress further compiler checks for that language.
set(CMAKE_C_COMPILER_WORKS 1)
You can skip the compiler checks by adding NONE to your project call:
project(<projectname> NONE)
but this can have pretty far-reaching effects. For full details, run
cmake --help-command project
I'm not familiar with ARM, so this is probably not your best option here. I guess you'd be better to see if there's a way to fix the -rdynamic flag.
EDIT:
It looks like this was identified as a bug which is effectively still unresolved. The comments in the bug report mention adding the following lines as a workaround (presumably before your project call):
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
It seems you target actually something else than Linux, so you should tell cmake that you are cross-compiling for the generic case:
SET(CMAKE_SYSTEM_NAME Generic)
Followed by (optionally, but nice to specify):
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_CROSSCOMPILING 1)
However, if you specify (which you likely did because this is stated in a lot of examples online):
SET(CMAKE_SYSTEM_NAME Linux)
Then cmake will load the configuration files from (suppose version 2.8) the file:
/usr/share/cmake-2.8/Modules/Platform/Linux.cmake
from which it is likely to load:
/usr/share/cmake-2.8/Modules/Platform/Linux-GNU.cmake
Here the -rdynamic flag is set for historical reasons:
macro(__linux_compiler_gnu lang)
# We pass this for historical reasons. Projects may have
# executables that use dlopen but do not set ENABLE_EXPORTS.
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")
endmacro()
Rather than disabling the tests as indeed is done by specifying NONE as the PROJECT argument, it seems setting the CMAKE_SYSTEM_NAME (to something else than Linux, for instance Generic) is what you actually want to do.
If you're just compiling a static library and you want to avoid having CMake test that the compiler can generate binaries, you can set the variable CMAKE_TRY_COMPILE_TARGET_TYPE.
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
When cross compiling for Windows, where there is no -rdynamic option, you can use
-DCMAKE_SYSTEM_NAME="Windows"
with cmake. Then Cmake will skip the test with -rdynamic.
I don't get it. I usually install third party software into /usr/local so libraries are installed into /usr/local/lib and never had problems linking to these libraries. But now it suddenly no longer works:
$ gcc -lkaytils -o test test.c
/usr/bin/ld.gold.real: error: cannot find -lkaytils
/usr/bin/ld.gold.real: /tmp/ccXwCkYk.o: in function main:test.c(.text+0x15):
error: undefined reference to 'strCreate'
collect2: ld returned 1 exit status
When I add the parameter -L/usr/local/lib than it works but I never had to use this before. Header files in /usr/local/include are found without adding -I/usr/local/include.
I'm using Debian GNU/Linux 6 (Squeeze) which has an entry for /usr/local/lib in /etc/ld.so.conf.d/libc.conf by default and the ldconfig cache knows the library I'm trying to use:
k#vincent:~$ ldconfig -p | grep kaytils
libkaytils.so.0 (libc6,x86-64) => /usr/local/lib/libkaytils.so.0
libkaytils.so (libc6,x86-64) => /usr/local/lib/libkaytils.so
So what the heck is going on here? Where can I check which library paths are searched by gcc by default? Maybe something is wrong there.
gcc -print-search-dirs will tell you what path the compiler checks. /usr/local/lib is simply not among them, so your compile time linker (in this case the new gold ld from binutils) doesn't find the library while the dynamic one (ld-linux.so which reads the cache written by ldconfig) does. Presumably the builds you've done previously added -L/usr/local/lib as necessary in their makefiles (usually done by a ./configure script), or you installed binaries.
This is probably an issue of environment variables - you have something set that's including /usr/local/include but not /usr/local/lib
From the GCC mapage on environment variables
CPATH specifies a list of directories to be searched as if speci‐
fied with -I, but after any paths given with -I options on the com‐
mand line. This environment variable is used regardless of which
language is being preprocessed.
and
The value of LIBRARY_PATH is a colon-separated list of directories,
much like PATH. When configured as a native compiler, GCC tries
the directories thus specified when searching for special linker
files, if it can’t find them using GCC_EXEC_PREFIX. Linking using
GCC also uses these directories when searching for ordinary
libraries for the -l option (but directories specified with -L come
first).
try "printenv" to see what you have set