Why does GNU ld default linker script NOT have 'MEMORY'? - linker

I checked the output of ld --verbose on both x86_64 as well as on armv7l (beaglebone black rev C). The default linker script does not contain 'MEMORY' command. Why is that?

Related

Using bzlib in C on macOS Catalina - "ld: symbol(s) not found for architecture x86_64", "clang: error: linker command failed with exit code 1"

I am attempting to compile a C program on macOS Catalina. The program will make use of bzip2 decompression. My code includes the line
#include <bzlib.h>
and I am trying to call the function BZ2_bzBuffToBuffDecompress. However, when I run gcc myfile.c -o myfile.c.o, I get the following error:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
I am just using a plain text editor and gcc, no IDEs and no CMake files. I suspect I may need a CMake file for this but I am not really sure how to proceed. Any assistance with this is greatly appreciated!
You need to link in the bzip library. gcc myfile.c -o myfile -lbz2. That command assumes the lib is installed into the standard location. Also, you are compiling a final executable so (by strong convention) it should not have a .o suffix.

GCC Compiler Optimizations, can't link with a main executable file '_' for architecture x86_64

*Antonio10ms$ gcc pi.c -o1 pi
ld: can't link with a main executable file 'pi' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I need help please to make an optimization to my .cpp
I think you are confusing the optimization argument with the output/target argument.
I think what you want is
gcc pi.c -o1 -o pi
where
"-o1" means "optimization level 1"
and
"-o pi" means "output to an executable named pi"

Trouble debugging C program in Eclipse on Yosemite

I am getting the following persistent errors trying to debug a C program in Eclipse Juno on my mac:
Building target: TimeStamps
Invoking: MacOS X C Linker
gcc -v -o "TimeStamps" ./graphic/arrow.o ./graphic/axesdraw.o . . .
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [TimeStamps] Error 1
So, I am confused about how to fix this in Eclipse. The main routing is in timestamp_test.c
I have -g -v as compiler flags, and -v as a linker flag.
No .o files are made.
Based on the the error given, you need to add the main function to timestamp_test.c.
Or pass the file that have the main function implemented to the compiler.

Xcode 5.1.1 build fail C programming

I am trying to build and run a basic C program in Xcode, but keep getting a "build failed" message. The script is nothing too crazy, just a natural number calculator, there's nothing wrong with the script as I've tested it on an online compiler and it works fine.
This is the full error message:
Ld /Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-ckojksceiqxrcdcfavsxvsgvapin
/Build/Products/Debug/testing.c normal x86_64
cd /Users/Matt/Code/testing.c
export MACOSX_DEPLOYMENT_TARGET=10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
/Developer/SDKs/MacOSX10.9.sdk -L/Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-
ckojksceiqxrcdcfavsxvsgvapin/Build/Products/Debug -F/Users/Matt/Library/Developer/Xcode/DerivedData
/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build/Products/Debug -filelist /Users/Matt/Library/Developer
/Xcode/DerivedData/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build/Intermediates/testing.c.build/Debug
/testing.c.build/Objects-normal/x86_64/testing.c.LinkFileList -mmacosx-version-min=10.9 -Xlinker
-dependency_info -Xlinker /Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-
ckojksceiqxrcdcfavsxvsgvapin/Build/Intermediates/testing.c.build/Debug/testing.c.build/Objects-
normal/x86_64/testing.c_dependency_info.dat -o /Users/Matt/Library/Developer/Xcode/DerivedData
/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build/Products/Debug/testing.c
duplicate symbol _main in:
/Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build
/Intermediates/testing.c.build/Debug/testing.c.build/Objects-normal/x86_64/tests.o
/Users/Matt/Library/Developer/Xcode/DerivedData/testing.c-ckojksceiqxrcdcfavsxvsgvapin/Build
/Intermediates/testing.c.build/Debug/testing.c.build/Objects-normal/x86_64/main.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Anybody know how to solve this? I've been searching for an answer for ages with no luck.
You have two "main" functions defined.
One in a file named "main.c" and the other in a "tests.c" file. Remove one of them and you should be okay!
Or, if you only have a "testing.c" file, do a Clean on your xcode project and try building again.

linker error cannot find symbol name in library

g++ (GCC) 4.7.2
3.7.6-201.fc18.x86_64 #1 SMP Mon Feb 4 15:54:08 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Fedora release 18 (Spherical Cow)
Hello,
I am compiling and having a problem trying to link a program.
The linker error is:
/usr/bin/ld: point.o: undefined reference to symbol '_Znwj##GLIBCXX_3.4'
/usr/bin/ld: note: '_Znwj##GLIBCXX_3.4' is defined in DSO /lib/libstdc++.so.6 so try adding it to the linker command line
/lib/libstdc++.so.6: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
This object file is point.o is trying to call a function that doesn't exist in libstdc++.
When I try and check if the symbol name does exist using readelf I can't find it.
readelf --all libstdc++.so.6.0.17 | grep _Znwj##GLIBCXX_3.4
Is this because the point.o is looking for a symbol in a older libstdc++ that could have been removed in a later version?
Many thanks for any suggestions,
In my case I was using gcc not g++. It used to work in '12, but a later build on a different machine in '14 choked. The gnu compiler has indeed changed. The answer in my case was to add
-lstdc++
onto the end of the linking line, as the error messages suggest. HTH.

Resources