So i got a makefile and when i run that i get this:
gcc -Wall -g -L. -DSTUDENT_MODE=1 -o lab2 lab2.c lab2_funcs.c advfuncs.o -lm
ld: warning: ignoring file advfuncs.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): advfuncs.o
Undefined symbols for architecture x86_64:
"__array", referenced from:
_main in lab2-bdc822.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
The makefile looks like this:
PROGRAM=lab2
SOURCES=lab2.c lab2_funcs.c
CFLAGS=-Wall -g -L.
all: $(SOURCES)
gcc $(CFLAGS) -DSTUDENT_MODE=1 -o $(PROGRAM) $(SOURCES) advfuncs.o -lm
#teacher: $(SOURCES)
# gcc $(CFLAGS) -DSTUDENT_MODE=0 -c advfuncs.c
# gcc $(CFLAGS) -o $(PROGRAM) $(SOURCES) advfuncs.o -lm
clean:
\rm -f lab2 lab2_funcs.o
I tried running this on eclipse on my windows machine but i get other errors. I even got a complete compiled version of the project by the teacher but i cant seem to run that either, i just get an error that i cant that binary file.
Related
I decided to learn how to make own OS by tutorial, I wrote boot on NASM and kernel on C also linker.ld and makefile. When I try linking all together I have this kind of error:
ld: library not found for -lgcc
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Also, I have installed binutils using homebrew but it doesn't help me. I have Mac OS 10.14
And this is my makefile:
CC = gcc
main: kernel.c linker.ld boot.asm
nasm -felf32 boot.asm -o boot.o
$(CC) -c kernel.c -o kernel.o -std=gnu99 -ffreestanding -Wall -Wextra
$(CC) -T linker.ld -o basilica.bin -ffreestanding -nostdlib boot.o kernel.o -lgcc
cp basilica.bin isodir/boot/basilica.bin
grub-mkrescue -o basilica.iso isodir
clean:
rm ./*.o ./*.bin ./*.iso ./isodir/boot/*.bin
What am I doing wrong? How can I fix this error: ld: library not found for -lgcc? Please help me.
Seems like an easy problem but I can't seem to find any resource on this...
My project tree is simple: main.c includes list.h, the end.
cmake_minimum_required(VERSION 3.7)
project(as03)
set(CMAKE_C_STANDARD 11)
set(SOURCE_FILES main.c list.h)
add_executable(as03 ${SOURCE_FILES} list.o)
This CMakeLists.txt file gives error:
/home/.../clion-2017.1.2/bin/cmake/bin/cmake --build /home/shawn/CLionProjects/CMPT300/as03/cmake-build-debug --target all -- -j 4
[ 50%] Linking C executable as03
/usr/bin/ld: ../list.o: relocation R_X86_64_32S against undefined symbol `headlist' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
CMakeFiles/as03.dir/build.make:96: recipe for target 'as03' failed
make[2]: *** [as03] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/as03.dir/all' failed
make[1]: *** [CMakeFiles/as03.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
EDIT: Environment is CLion IDE on Linux with gcc 6.3.0.
EDIT2: My apologies, the
relocation R_X86_64_32S against undefined symbol `headlist' can not be used when making a shared object
error is not an issue of CMake, but was reproducible with command-line compiling of the corresponding makefile:
CC=gcc
CFLAGS=-w -std=c11
PROG=simulation-app
OBJS= main.o list.o
simulation-app: $(OBJS)
$(CC) $(CFLAGS) -o $(PROG) $(OBJS)
main.o: main.c
$(CC) $(CFLAGS) -c main.c
clean:
ls | grep -v list.o | grep .o | xargs rm
Turns out one of my peers have encountered this problem and was solved by re-installing a fresh linux-distro... No thanks.
So it seems like a machine-dependent problem. I have tried downgraded my gcc version to 5.4.1 to match the machine where this .o was compiled on, but nothing changed :(
add_executable(as03 main.c list.c)
You should only use sources in the list after the target, not object files.
You also don't need headers in the list unless you use or want to support IDEs (especially Visual Studio).
I have to build a project with shared objects compiled on a other x64_86 computer. I have this error:
cc -std=c11 -Wall -Werror -Wextra -pedantic -I./include src/server.c
obj/tftp.o -o bin/server -L./lib64 -lSocketUDP -lAdresseInternet -lpthread
ld: warning: ld: warning: ignoring file ./lib64/libSocketUDP.so, file was
built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture
being linked (x86_64): ./lib64/libSocketUDP.soignoring file
./lib64/libAdresseInternet.so, file was built for unsupported file format (
0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 ) which is not the architecture being linked (x86_64):
./lib64/libAdresseInternet.so
The architecture of my Mac is x86_64 and shared objects were compiled on a x86_64. The compilation works on my Linux computer.
Here my Makefile:
CFLAGS = -std=c11 -Wall -Werror -Wextra -pedantic -I./include
LDLIBS = -L./lib64
LDFLAGS = -lSocketUDP -lAdresseInternet -lpthread
all: obj/tftp.o bin/server bin/client
obj/tftp.o: src/tftp.c
mkdir -p obj
$(CC) $(CFLAGS) -c $^ -o $#
bin/server: src/server.c obj/tftp.o
mkdir -p bin
$(CC) $(CFLAGS) $^ -o $# $(LDLIBS) $(LDFLAGS)
bin/client: src/client.c obj/tftp.o
mkdir -p bin
$(CC) $(CFLAGS) $^ -o $# $(LDLIBS) $(LDFLAGS)
clean:
$(RM) -r obj
distclean:
$(RM) -r obj bin
Thank you.
You cannot do that as this "other x86_64 computer" was clearly running Linux and generating ELF-format object files.
0x7F 0x45 0x4C 0x46
0x7F 'E' 'L' 'F'
OSX/iOS uses Mach-O format object files and cannot be linked against different types of object file.
You will need to compile all the code under OSX.
Your SocketUDP lib is probably built for Linux. Linux and OS X use different and incompatible object files, ELF vs . Mach-O.
You have to build the library on OS X as well.
I've written an entire program and its makefile, the only trouble is I have to idea how to implement the debugger. I've been looking at similar questions online but to no avail.
Here's my makefile:
# the variable CC is the compiler to use.
CC=gcc
# the variable CFLAGS is compiler options.
CFLAGS=-c -Wall
assign4: main1.o ObjectManager.o
$(CC) main1.o ObjectManager.o -o assign4
main1.o: main1.c ObjectManager.h
$(CC) $(CFLAGS) main1.c
ObjectManager.o: ObjectManager.c ObjectManager.h
$(CC) $(CFLAGS) ObjectManager.c
clean:
rm -rf *o assign4
I've tried to adjust the CFLAGS: to -g Wall, but all it says is:
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: *** [ObjectManager.o] Error 1
Any suggestions to fix this?
Look at this rule:
ObjectManager.o: ...
$(CC) $(CFLAGS) ObjectManager.c
If CFLAGS is -c -Wall, that -c means that gcc will compile the source file, but not attempt to link it. This is exactly what was intended, to produce an object file and not an executable. One consequence of this is that the source dile (ObjectManager.c) need not contain a main function-- the compiler trusts you to provide one at link time.
But if CFLAGS is -g -Wall, the -g does not imply -c. So gcc will attempt to create an executable, and abort if main is not present.
Solution:
CFLAGS := -Wall -g # the -g can be added with a conditional if you like
ObjectManager.o: ...
$(CC) $(CFLAGS) -c ObjectManager.c
i try to compile a 32 bit app on my mac osx 64bit
I have a 32bit lib included.
I try to create a personal lib
gcc -m32 -c fileA.c -Iinclude -o fileA.o
gcc -m32 -c fileB.c -Iinclude -o fileB.o
All Ok
now I create .a File
ar ruv ./lib/myLib.a fileA.o fileB.o
When I try to launch
gcc -m32 -o imageMod imageMod.c -Iinclude -Llib
I receive the following error
Undefined symbols for architecture i386: "_addozzo", referenced
from:
_main in imageMod-nfyyGP.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1
(use -v to see invocation)
anyone can help me?
You need to tell gcc to link in the library:
gcc -m32 -o imageMod imageMod.c -Iinclude -Llib -l:myLib.a