FAQ Database Discussion Community


Library compiling errors with alternate build of gcc

gcc,ld,hdf5
I have some fortran programs that would not compile in old versions of gfortran. I have to run multiple instances of this program and am using another system (a cluster system) which has centos5_x64 with gcc-4.1 !! Therefore I had to build new version of gcc; I built both gcc-4.8.3...

GCC: How to stop gcc from creating random temporary file name for the .o files

c,gcc,ld
I am attempting to compile two .c files using the following gcc command: gcc -O0 program1.c program2.c -o output.elf and all is fine until I pass in a linker script and view the map file. gcc -O0 program1.c program2.c -o output.elf -Xlinker -T memory.ld -Xlinker custom.ld of which my custom.ld...

How to insert data into compiled binary for MCU

c,linker,microcontroller,ld,linker-scripts
I am trying to insert a md5 hash of part of my binary into the binary, for keeping track of MCU FW version. I have approached it like this: in the link script I have split the flash in two sections MEMORY { FLASH0 (rx) : ORIGIN = 0x8000000, LENGTH...

Link and call two separate mains

c,gcc,linker,ld
Is it possible through some linker magic to link together two files with two separate main()s, then add a third controlling main() that would decide at run time which of the other two mains to call? So imagine: /* test1.c */ include <stdio.h> int main() { printf("Test1\n"); } /* test2.c...

link c and assembly

c,gcc,assembly,ld
I have a very simple main.c file: #include <stdio.h> int cnt; extern void increment(); int main() { cnt = 0; increment(); printf("%d\n", cnt); return 0; } And even simpler hello.asm: EXTERN cnt section .text global increment increment: inc dword [cnt] ret First I get main.o by typing gcc -c main.c...

Linux - process killed when linking section into lowest 2 MB of memory?

linux,linker,ld,virtual-memory,linker-scripts
I'm learning about LD linker scripts, and I noticed that if I link the .text section (or any section) at an address lower than than 2 MB, my process gets instantly killed by Linux as soon as I run it. Here's an example script I'm using: SECTIONS { . =...

How does using -L affect the linker?

linux,ubuntu,gcc,linker,ld
I'm rather new on Linux, so maybe this is a simple question. The question is: How does adding a -L/path affect the linker when there are no libraries attached? my issue: I'm trying to set up a cross-compilation toolchain featuring two pieces of third-party libraries¹. I'm using the linaro arm-linux-gnueabihf-raspbian...

NVCC CUDA cross compiling cannot find “-lcudart”

linux,cuda,ld,nvcc
I have installed CUDA 5.0 and NVCC on my Ubuntu virtual machine and have had problems compiling even a basic CUDA C program. The error is as follows: [email protected]:~/CUDA$ nvcc helloworld.cu -o helloworld.o -target-cpu-arch=ARM -ccbin=/usr/bin/arm-linux-gnueabi-gcc-4.6 --machine=32 /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: skipping incompatible /usr/local/cuda-5.0/bin/../lib/libcudart.so when searching for -lcudart /usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: skipping incompatible...

gentoo ld.gold failed on sys-libs/db

c,linker,ld,gentoo,gold-linker
I've recently switched from default binutils linker ld.bfd to ld.gold (to get link time optimization working and why not?). It was made by manual (like here: http://wiki.gentoo.org/wiki/Gold). As the result I got chain of symlinks from /usr/bin/ld to ld.gold binary, so linker was changed transparently for build process. But when...

How to compile libusb as shared library?

gcc,shared-libraries,ld,autotools,libusb-1.0
I am trying to build libusb as shared library as follows. Following are two steps. 1. Configure 2. Make. I pass "--enable-shared" to configure script assuming it will generate the shared .so file Configure ./configure CC=/mnt/store/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin/arm-linux-gnueabihf-gcc --host=arm-linux --enable-udev=no --enable-shared checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment...

How to change the name of executable entry point from main to something else?

c,gcc,linker,ld,elf
I'm trying to compile third party source code using gcc 4.8 on Ubuntu Linux (12.04 x64) with a lot of utilities and test applications where executable entry point is not called main. Don't ask me why - I don't know the answer. Linker of course complains: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':...

Error “library not found for -lPods-MyProjectTests-KIF” when installing KIF in existing workspace

xcode6,integration-testing,cocoapods,ld,kif
I run into this error when adding KIF to an existing Xcode 6 workspace: ld: library not found for -lPods-MyProjectTests-KIF What may be special about my situation that MyProject.xcworkspace/ resides in the parent directory of MyProject.xcproject/ (and depends on several other sibling projects as well): ./MyProject.xcworkspace/ ./MyProject/ ./MyProject/MyProject.xcworkspace/ ./MyProject/Podfile My...

Dynamically linking from a static libarary?

linux,static-libraries,ld
I'm currently attempting to rebuild FlightGear on my Ubuntu 14.04 machine. Everything went smoothly until I decided to build fgrun which requires Qt. I decided to compile Qt as a static library since I didn't want self-built libraries overrunning any on the system. I statically built Qt on the system...

ld not finding existing library

linux,ld,gfortran,hdf5
I am compiling a fortran code that requires hdf5 libraries which are installed in a local directory. This is my Makefile: FC = gfortran FCFLAGS = -g -fcheck=all -Wall -fdefault-real-8 INCLUDES = -I/home/bharat/hdf5/include LFLAGS = -L/home/bharat/hdf5/lib LIBS= -lhdf5_fortran main: main.o param.o dmotifs.o ssa.o $(FC) $(LFLAGS) $(LIBS) -o main $^ param.o:...

Segmentation fault in x86 example program

assembly,x86,segmentation-fault,ld,gas
I'm reading this book Programming From the Ground Up, Jonathan Bartlett. On this program that shows the function calling conventions for the first time I'm getting a segmentation fault when running it after typing it just like in the book. The function just takes 2 numbers from the stack, and...

gcc links to wrong GLIBCXX version when O2 flag is specified

c++,linux,gcc,linker,ld
I have a shared library file which I build using a Makefile. I ran into an issue where, after building the library, I'd get the dreaded GLIBCXX_ not found linker error. This case is particularly strange. When I compile with the -g3 flag, I don't get the error. If I...

How to build a './configure && make && make install' software against a custom library which I also build?

linux,make,gnu,ld,configure
I am building tmux-2.0 from sources on a pretty regular Linux host. First attempt failed as it turned out that the version of libevent installed is older than required, so I proceeded to download and build libevent-2.0.22 from sources (current at the time of writing) first. Building of libevent succeeded...

Compiled static executable returns “no such file or directory”

c++,gcc,cmake,ld
I'm trying to static compile my c++ executable. Everything works fine usually, but I'm trying to compile it statically. Here is the linker line: /usr/bin/c++ -O3 -static -static-libgcc -static-libstdc++ main.cpp.o xor.cpp.o other.cpp.o -o myprogram -rdynamic -Wl,-Bstatic -lssl -lcrypto -lprotobuf-lite /usr/local/lib/libboost_filesystem.a /usr/local/lib/libboost_system.a /usr/local/lib/libboost_program_options.a /usr/local/lib/libboost_regex.a /usr/local/lib/libboost_thread.a /usr/local/lib/libboost_chrono.a -lgmodule-2.0 -lglib-2.0...

What happens when ld link different versions of the same library

c++,shared-libraries,ld
Let's say I have libA.so with version 1.1 and 1.2, both have the same symbols defined. what happens if myApp need a symbol from libA but mistakenly linked both versions: ld -o myApp -Lpath -lA_1_1 -lA_1_2 Am I right it will use symbols from the first one as long as...

ARM, .COMMON section and -fno-common flag

gcc,linker,arm,ld
I'm trying to diagnose a problem. The problem is my program works fine if I place a printf (specifically printf) in the beginning of the program, and it doesn't if I don't. The issue is very specific to a loop that reads systick variable that I increment in systick_handler. If...

What's the proper way to link against an executable on Windows?

c++,windows,mingw,ld,mingw-w64
I need to use some symbols from the main executable in a plugin. Linking against the executable causes the following linker errors: i686-w64-mingw32-g++ example.cpp -shared -I.. -std=c++11 -o test.dll ../../test.exe -static-libgcc -static-libstdc++ -fvisibility=hidden [..]/test.exe:cygming-crtbegin.c:(.text+0x500): multiple definition of `__gcc_register_frame' /usr/lib/gcc/i686-w64-mingw32/5.1.0/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here [..]/test.exe:cygming-crtbegin.c:(.text+0x560): multiple definition of...

Detecting unresolved symbols in an ELF executable

c,linux,shared-libraries,ld,elf
Let's say I have two files: // shared.c (will be compiled to 'shared.so') #include <stdio.h> int f() { printf("hello\n"); } and // exe.c (will be compiled to 'exe') #include <stdio.h> int f(); int main() { int i; scanf("%d", &i); if (i == 5) f(); } I compile both files as...

Is binary linked with gold linker running faster?

c++,ubuntu,linker,ld,gold-linker
Running simulation code using GEANT4 (large Monte Carlo C++ simulation framework, lots of shared libraries). Compiled and linked GEANT and my app with gold linker and with standard BFD based linker. Looks like gold one is running a bit faster (1'47" vs 1'51"). Could someone shed a light what would...

Why should “data = .;” be repeated three times in a linker script?

linker,ld,elf
I saw this link script in http://www.jamesmolloy.co.uk/tutorial_html/1.-Environment%20setup.html SECTIONS { .text 0x100000 : { code = .; _code = .; __code = .; // What is this line for? *(.text) . = ALIGN(4096); } .data : { data = .; _data = .; __data = .; *(.data) *(.rodata) . = ALIGN(4096);...

Eclipse ARM mbed cannot move location counter backward error

eclipse,ld,mbed
while I was following this tutorial https://developer.mbed.org/cookbook/eclipse-for-building-and-debugging I run on a error building the project on Eclipse (I followed all the steps untill the first build project at which point I received the following error): ../../external/mbed/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/TOOLCHAIN_GCC_ARM/TARGET_LPC11U24_401/LPC11U24.ld:50 cannot move location counter backwards (from 00000238 to 00000200) collect2: error: ld returned 1...

How to resolve undefined symbols for architecture i386

ios,xcode,linker,ld
I've recently downloaded some source from a git repository into Xcode 6.1.1. However, I'm getting "missing required architecture i386" for a library that's include with the app (and existing on my filesystem). Here's the error: ld: warning: ignoring file /Users/myname/Documents/mycomp-mycompapp-ios/mycomp/libs/zbar_iOS7_Fix/libzbar.a, missing required architecture i386 in file /Users/myname/Documents/mycomp-mycompapp-ios/mycomp/libs/zbar_iOS7_Fix/libzbar.a (3 slices) Undefined...

How to debug program with custom elf interpreter?

debugging,gdb,ld,elf
I can debug some program (say /bin/ls) like this: [[email protected] ~]$ gdb -q --args /bin/ls Reading symbols from /bin/ls...Reading symbols from /bin/ls...(no debugging symbols found)...done. (no debugging symbols found)...done. Missing separate debuginfos, use: debuginfo-install coreutils-8.22-19.fc21.x86_64 (gdb) start Temporary breakpoint 1 at 0x402990 Starting program: /usr/bin/ls [Thread debugging using libthread_db enabled]...