This is my linker command:
arm-none-eabi-ld boot_and_link/startup.o drivers/gpio.o ../programs/dmips/dhry_1.o ../programs/dmips/dhry_2.o -nostartfiles -T boot_and_link/linker.ld -L/usr/lib/gcc/arm-none-eabi/4.8/armv6-m -lgcc -L/usr/lib/arm-none-eabi/newlib/armv6-m/ -lc -L/usr/lib/arm-none-eabi/newlib/armv6-m/ -lnosys -o ../programs/dmips/dmips.elf
I'm using, my own startup code and my own linker script since I'm doing a bare metal compilation in an attempt to run Dhrystone benchmark on an Cortex M0 processor.
These are the errors I get:
/usr/lib/arm-none-eabi/newlib/armv6-m//libc.a(lib_a-fvwrite.o): In function `__sfvwrite_r':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/armv6-m/newlib/libc/stdio/../../../../../../newlib/libc/stdio/fvwrite.c:196: undefined reference to `__aeabi_idiv'
/usr/lib/arm-none-eabi/newlib/armv6-m//libnosys.a(sbrk.o): In function `_sbrk':
/home/tin/projects/debian/arm-toolchain/collab-maint/newlib/build/arm-none-eabi/armv6-m/libgloss/libnosys/../../../../../libgloss/libnosys/sbrk.c:14: undefined reference to `end'
The end symbol, as I understand it, should be the end of the heap right? I can get rid of it by setting it in the linker script.
However the other one is wierd. That symbol is declared in libgcc.a which is included.
In my opinion the problem is a simple path conflict: whatever fvwrite.o is, it wants to use that symbol and the linker is not looking for it in libgcc.a which exists and is added as parameter library. Keep in mind this is just a thought. I don't really know what is going on.
Any ideas?
Related
Thanks for taking my question. I have spent many hours checking posts on this but I still need help. Thanks for being patient with me :)
I have a class of midi functions that calls the Widows multimedia API.
When I compile my class Midf.h by itself at the command line it compiles and works:
g++ -Wall Midf.h Midf.cpp midftest.cpp -lwinmm -o midftest2.exe
I have written a makefile to include these functions in a larger program.
My recipe for building the Midf.o is as follows:
Midf.o: Midf.cpp Midf.h
g++ -Wall Midf.cpp -lwinmm
At this point I get the following error:
g++ -Wall Midf.cpp -lwinmm
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/libmingw32.a(main.o): In function `main':
e:\p\giaw\src\pkg\mingwrt-4.0.3-1-mingw32-src\bld/../mingwrt-4.0.3-1-mingw32-src/src/libcrt/crt/main.c:91: undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
Makefile:21: recipe for target 'Midf.o' failed
make: *** [Midf.o] Error 1
I have read that Mingw does not support wmain, but there is a way around that by making sure that main is defined properly outside of a namespace. I am not sure how to do that.
I would be glad to post the entire makefile, my file that contains main(), Midf.h Midf.cpp or any other file in the source code to find the problem.
By the way, this is a console program and I have tried building it with MinGW and with Cygwin.
Thanks again for everyone willing to help!
To turn my comments into an answer:
If you want to perform separate compilation you have to tell gcc not to link your objects by passing the -c flag.
Your second problem was not passing the libraries during linking, passing them during compilation has no effect.
On building Glibc on my toolchain . The libraries make succesfully (and test ok) all FLAGS unset except for those specified for building default glibc. then i start building the programs both with and without FLAGS on seperate fresh build attempts and every time something in the iconv folder always breaks...
I'll diverge for a second to moan how its always iconv that breaks in GLibc for me and always has done for as long as i can remember... moving on though....
When gcc-4.8.0 is passed gcc -nostdlib -nostartfiles -o /glibc-build/iconv/iconvconfig -Wl,-dynamic-linker=/tools/lib/ld-linux-x86-64.so.2 -Wl,--hash-style=both -Wl,--warn-shared-textrel,--fatal-warnings /glibc-build/csu/Scrt1.o /glibc-build/csu/crti.o gcc --print-file-name=crtbeginS.o /glibc-build/iconv/iconvconfig.o /glibc-build/iconv/strtab.o /glibc-build/iconv/xmalloc.o /glibc-build/iconv/hash-string.o -Wl,-rpath-link=/glibc-build:/glibc-build/math:/glibc-build/elf:/glibc-build/dlfcn:/glibc-build/nss:/glibc-build/nis:/glibc-build/rt:/glibc-build/resolv:/glibc-build/crypt:/glibc-build/nptl /glibc-build/libc.so.6 /glibc-build/libc_nonshared.a -Wl,--as-needed /glibc-build/elf/ld.so -Wl,--no-as-needed -lgcc gcc --print-file-name=crtendS.o /glibc-build/csu/crtn.o
gcc -nostdlib -nostartfiles -o /glibc-build/iconv/iconv_prog -Wl,-dynamic-linker=/tools/lib/ld-linux-x86-64.so.2 -Wl,--hash-style=both -Wl,--warn-shared-textrel,--fatal-warnings /mnt/lfs/glibc-build/csu/Scrt1.o /glibc-build/csu/crti.o gcc --print-file-name=crtbeginS.o /glibc-build/iconv/iconv_prog.o /glibc-build/iconv/iconv_charmap.o /glibc-build/iconv/charmap.o /glibc-build/iconv/charmap-dir.o /glibc-build/iconv/linereader.o /glibc-build/iconv/dummy-repertoire.o /glibc-build/iconv/simple-hash.o /glibc-build/iconv/xstrdup.o /glibc-build/iconv/xmalloc.o -Wl,-rpath-link=/glibc-build:/glibc-build/math:/glibc-build/elf:/glibc-build/dlfcn:/glibc-build/nss:/glibc-build/nis:/glibc-build/rt:/glibc-build/resolv:/glibc-build/crypt:/glibc-build/nptl /glibc-build/libc.so.6 /glibc-build/libc_nonshared.a -Wl,--as-needed /glibc-build/elf/ld.so -Wl,--no-as-needed -lgcc gcc --print-file-name=crtendS.o /glibc-build/csu/crtn.o
i get 2 pages of referencing issues
/glibc-build/iconv/iconvconfig.o: In function more_help':
iconvconfig.c:(.text+0x12e): undefined reference to__tsan_func_entry'
iconvconfig.c:(.text+0x136): undefined reference to __tsan_write8'
iconvconfig.c:(.text+0x150): undefined reference to__tsan_func_exit'
iconvconfig.c:(.text+0x1cc): undefined reference to __tsan_read8'
/glibc-build/iconv/iconvconfig.o: In functionalias_compare':
iconvconfig.c:(.text+0x226): undefined reference to __tsan_func_entry'
iconvconfig.c:(.text+0x233): undefined reference to__tsan_read1'
iconvconfig.c:(.text+0x246): undefined reference to __tsan_read8'
iconvconfig.c:(.text+0x25d): undefined reference to__tsan_read1'
iconvconfig.c:(.text+0x26e): undefined reference to __tsan_read8'
iconvconfig.c:(.text+0x282): undefined reference to__tsan_func_exit'
iconvconfig.c:(.text+0x2b4): undefined reference to __asan_report_load8'
iconvconfig.c:(.text+0x2b9): undefined reference to__asan_report_load8'
/glibc-build/iconv/iconvconfig.o: In function module_compare':
iconvconfig.c:(.text+0x2fb): undefined reference to__tsan_func_entry'
iconvconfig.c:(.text+0x308): undefined reference to __tsan_read1'
iconvconfig.c:(.text+0x326): undefined reference to__tsan_read8'
iconvconfig.c:(.text+0x337): undefined reference to __tsan_read1'
iconvconfig.c:(.text+0x34a): undefined reference to__tsan_read8'
iconvconfig.c:(.text+0x36f): undefined reference to __tsan_func_exit'
iconvconfig.c:(.text+0x3a6): undefined reference to__asan_report_load8'
iconvconfig.c:(.text+0x3ab): undefined reference to __asan_report_load8'
/glibc-build/iconv/iconvconfig.o: In functionname_compare':
after 2 weeks of trying to get it to compile every which way possible im getting a bit fed up. Any ideas please?
Emma
A bit late, but hopefully useful.
The symbols with tsan and asan in their name are related to the address sanitizer project that provides LLVM clang and gcc with tools to detect and report a whole range of problems related to illegal memory access.
To use them you have to install tools and libraries, use the correct versions of the compilers and the correct combinations of flags during compile and linking depending on your version.
In my experience the documentation is only so useful, and the topic is pretty advanced. In my project over which I have full control, I ended up disabling all but the one commandline parameter -fsanitize=address together with the recommended -fno-omit-frame-pointer for both compile and link (gcc 4.8 on x64 ubuntu 14.04LTS).
Since you are attempting to build an existing project, you are at the mercy of their settings. I would look at docs for that project and try to determine the recommended versions of compiler and sanitizer tools from there, or maybe some configuration options to disable it if you don't care.
I need an help!! I am trying to build a standalone executable ie without ANY dynamic linking.
I wrote a small test program, generated a relocatable object file for it called test.o. When I try to build the standalone executable using GNU linker I get the below error:
$ld -static -o test test.o /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/libc.a /usr/lib/gcc/i486-linux-gnu/4.4/libgcc.a /usr/lib/gcc/i486-linux-gnu/4.4/libgcc_eh.a
/usr/lib/gcc/i486-linux-gnu/4.4/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function _Unwind_Find_FDE':
(.text+0x190b): undefined reference todl_iterate_phdr'
How to resolve the undefined symbol dl_iterate_phdr. In which archive this symbol is present?
Thanks!!!
EDIT1:
Just in case if I am not very clear, my motive is to generate a standalone executable ie an executable which is completely ready for execution while it gets loaded into memory i.e.) all symbol resolution and relocation is done by program linker itself instead of dynamic linker. Is it possible to generate such an executable?
FINAL UPDATE:
Now I got it to get complied with ld directly using the below command:
$ld -static -o test /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.4.3/crtbeginT.o /usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o test.o --start-group /usr/lib/gcc/i486-linux-gnu/4.4.3/libgcc.a /usr/lib/gcc/i486-linux-gnu/4.4.3/libgcc_eh.a /usr/lib/libc.a --end-group
man ld says --start-group archives --endgroup is used to resolve circular references!! Also i find symbol dl_iterate_phdr is defined in libc.a.
Thanks all for your help!!
When I try to build the standalone executable using GNU linker
Don't. Use of ld to link any user-space program is most often a bug. Your link line is certainly incorrect.
Use compiler driver to do the heavy lifting for you. This should work:
gcc -static -o test test.o
I am looking to use ld since I wanted to build a standalone executable
What makes you believe that GCC-built executable is less stand-alone than ld-built one? Whatever it is, you are mistaken: gcc simply invokes ld with correct arguments.
If you're getting this error when targeting android, you need to link against libdl.so (-ldl)
gcc -o main main.c -L . -static-libgcc -Wl,-static -lhello -lc
I am trying to build a tool called sscep (http://www.klake.org/~jt/sscep/) for Windows. It does not run natively and I have a "patch" that changes sscep to make it compile on Windows.
After applying the patch, it does compile perfectly but the linker screws. I am using gcc in minGW/msys
The original messsage was that it couldn't find the crypto lib so I added the library with "-L../openssl-mingw/lib" which then didn't create any more errors. I also have the command line switch -lcrypto in my command: gcc -L../openssl-mingw/lib -lcrypto sscep.o init.o net.o sceputils.o pkcs7.o ias.o fileutils.o -o sscep.In this directory is a libcrypto.a. OpenSSL itself was compiled with the exact same compiler just running ./config && make && make test && make install. Also the sources were extracted using the minGW tar and not 7-zip.
After following all documentation this is my (truncated) output:
sscep.o:sscep.c:(.text+0x83): undefined reference to `WSAStartup#8'
sscep.o:sscep.c:(.text+0xa5): undefined reference to `WSACleanup#0'
sscep.o:sscep.c:(.text+0x3d5): undefined reference to `BIO_new_mem_buf'
sscep.o:sscep.c:(.text+0x3e0): undefined reference to `ASN1_INTEGER_new'
sscep.o:sscep.c:(.text+0x414): undefined reference to `a2i_ASN1_INTEGER'
sscep.o:sscep.c:(.text+0x432): undefined reference to `ASN1_INTEGER_to_BN'
sscep.o:sscep.c:(.text+0x448): undefined reference to `BN_bn2dec'
sscep.o:sscep.c:(.text+0xb7e): undefined reference to `EVP_des_cbc'
sscep.o:sscep.c:(.text+0xbaf): undefined reference to `EVP_bf_cbc'
sscep.o:sscep.c:(.text+0xbda): undefined reference to `EVP_des_cbc'
sscep.o:sscep.c:(.text+0xc02): undefined reference to `EVP_des_ede3_cbc'
sscep.o:sscep.c:(.text+0xc48): undefined reference to `EVP_md5'
sscep.o:sscep.c:(.text+0xc79): undefined reference to `EVP_md5'
sscep.o:sscep.c:(.text+0xca1): undefined reference to `EVP_sha1'
This goes on for every file in there and supposedly every function called.
Searching here and google resulted in a missing library but omitting the -L directive from above I get another error about not finding libcrypto. So I assume that the library is actually found but somewhat with wrong addresses or something?
Here my compiler/linker knowledge actually ends.
If it is possible that the patch is responsible for that (which I do not believe since these are all openssl functions and the compiling works) then I can provide you with it.
Edit: Is there any information that I should provide so someone can help me? The version of openssl is 1.0.1 if this makes any difference.
On this topic: If it does make a difference, could this error occur because of a wrong version. As far as I understand linker theory, this error should not originate from a wrong version unless all of the below functions were replaced by differently named ones (but then the compiler would have complained, I guess?).
Another addition: Since I am on a 64 bit Windows 7, I tried to compile it with -m32 flag but that did not help. I assume since mingw is already 32 bit only, I can't even build x64. Another question is whether it is a problem that I am running in a virtualized environment on an AMD Opteron while openssl is built with the command "-march=i486"?
With some help I could finally figure this out! It was a problem of the order AND a problem of missing libraries. The combination killed me.
The libraries had to be -lcrypto -lws2_32 -lgdi32 not just -lcrypto. Furthermore, I had to append the libraries after the object files, so: $(CC) $(CFLAGS) $(OBJS) -lcrypto -lws2_32 -lgdi32 -o $(PROG) was the right make line.
Finally with this, it compiles fine. I didn't even need any architecture flags and such.
and sorry for my not really good english. I'll try my best :)
I am trying to compile a addin for my Casio graphic calculator in C. This works without problems when using the official SDK. Because it is only available for Windows, I want to use gcc.
So I got sh-rtems-gcc and it's binutils from macports and tried to compile my program according to this instructions. I copy-pasted the described addin.ld and crt0.s and placed my main.c and libfxsys.a (from the same guys as the instructions mentioned above) in the same directory. The sub-dir include contains fxsys' headers. I verified the presence of all the functions of the library in the .a file with nm.
When using this command for compilation:
sh-rtems-gcc-4.2.3 -m3 -mb -nostdlib -I./include -c crt0.s main.c
Everything works fine. But then im trying to link:
sh-rtems-gcc-4.2.3 -m3 -mb -nostdlib -L. -o myaddin.elf -Taddin.ld crt0.o main.o -lfxsys
and get the following error:
main.o: In function `__main':
main.c:(.text+0x248): undefined reference to `_Bdisp_AllClr_VRAM'
...
... (--- cut 16 other errors in the same format ---)
...
main.c:(.text+0x360): undefined reference to `_Sleep'
./libfxsys.a(locate.o): In function `_locate':
locate.c:(.text+0x28): undefined reference to `_locate_OS'
collect2: ld gab 1 als Ende-Status zurück
All the missing symbols are in the libfxsys.a. I have verified this with nm.
I have already played with the positions of the library in the command, as this is often mentioned as a source of failure in other posts found in google, but without success. I also tried adding and removing the -lgcc option that is used in the above mentioned instructions, without success.
My Host-Machine is a Intel Mac, OS X 10.6
Because I have no idea how to solve this problem, and get to compile my program, I have to ask: What am I doing wrong? How can I compile my program without using the SDK?
Thanks in advance,
xythobuz
Edit:
I have also tried linking with:
sh-rtems-ld -EB -L. -o myaddin.elf -Taddin.ld crt0.o --start-group main.o libfxsys.a --end-group
But it produces the same output as above.
I can't say the exact problem, but would investigate like this:
Find the library that contains the missing symbols. Use nm to see symbol names
Once you know which library contains the symbols make sure you're linking to it, and in the correct order. Try using recursive symbol resolution options -( -) with your linker.