I have write a simple makefile
1 LIBS= -L /usr/local/pgsql/lib
2 INCL= -I /usr/local/pgsql/include -I/home/name/
3
4 pg: pg.o
5 gcc -o pg pg.o $(LIBS) -lpq
6
7 pg.o: pg.c
8 gcc -c $(INCL) $(LIBS) pg.c
Under the folder of name, there are three files: pg.c, timer.c, timer.h
but it reports error of could not find timefunctions. what's wrong with my makefile? thanks.
The error is
gcc -o pg pg.o -L /usr/local/pgsql/lib -lpq
pg.o: In function `main':
pg.c:(.text+0x91): undefined reference to `createTimer'
pg.c:(.text+0xa1): undefined reference to `startTimer'
pg.c:(.text+0x167): undefined reference to `endTimer'
...
pg.c:(.text+0x214): undefined reference to `displayTimer'
pg.c:(.text+0x220): undefined reference to `destroyTimer'
collect2: error: ld returned 1 exit status
make: *** [pg] Error 1
You haven't given us enough information to be certain, but it might be enough to add timer.o to the prerequisite list of the pg rule:
pg: pg.o timer.o
gcc -o pg $^ $(LIBS) -lpq
Related
Trying to link a program which (for unknown reasons) generates a reference to "xmemdup".
I found the source code for xmemdup.c, and compiled it, and included the .o file in the link, but ld still claims it is undefined.
$ gcc -Wall -g -O2 -pipe -DBINDIR=\"/usr/bin\" -c -o rsh.o rsh.c
This worked, generating rsh.o
$ ll rsh.o ../publib-0.40/alloc/xmemdup.o
-rw-r--r-- 1 perryh perryh 2344 Dec 29 22:25 ../publib-0.40/alloc/xmemdup.o
-rw-r--r-- 1 perryh perryh 68656 Dec 30 00:47 rsh.o
Proves that the .o files I am about to pass to the linker do exist. BTW xmemdup.o is an object file, not a library, so it should get included unconditionally even if it were not needed to resolve a reference.
$ gcc -Wall -g -O2 -pipe -DBINDIR=\"/usr/bin\" -o rsh rsh.o ../publib-0.40/alloc/xmemdup.o
/usr/bin/ld: symbol lookup error: /usr/bin/ld: undefined symbol: xmemdup
collect2: error: ld returned 127 exit status
and yet the linker can't see the definition of xmemdup in xmemdup.o
I've install raylib according to this wiki page.
My Project Folder is look like this:
[this][1]
> ..\build>mingw32-make
g++ ../main.cpp -o test.exe -O2 -Wall -Wno-missing-braces -I ../include/ -L ../lib/ -lraylib -lopeng132 -lgdi32 -lwinmm
D:/Software/raylib/mingw/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lopeng132
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [Makefile:2: default] Error 1```
[1]: https://i.stack.imgur.com/QK2X3.png
It seems you have typed openg132 instead of opengl132. You have mistaken the letter l for the number 1
I'm trying to compile some source code from a makefile, but its not working. The error I get is
gfortran-9 -o sams43 sams43.o mvnorm.o isml_wrapper.o
/usr/bin/ld: sams43.o: relocation R_X86_64_32 against '.rodata' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
make: *** [makefile:7: sams43] Error 1
Here's my makefile:
FC=gfortran-9
FCFLAGS= -g
all: sams43 normal_dataset
sams43: sams43.o mvnorm.o imsl_wrapper.o
${FC} -o sams43 sams43.o mvnorm.o imsl_wrapper.o
imsl_wrapper.o: imsl_wrapper.f90
${FC} ${FCFLAGS} -c imsl_wrapper.f90
sams43.o: sams43.f90
${FC} ${FCFLAGS} -c sams43.f90
mvnorm.o: mvnorm.f90
${FC} ${FCFLAGS} -c mvnorm.f90
normal_dataset: normal_dataset.o mvnorm.o
${FC} -o normal_dataset normal_dataset.o mvnorm.o
normal_dataset.o: normal_dataset.f90
${FC} ${FCFLAGS} -c normal_dataset.f90
clean:
# rm *.o sams43 normal_dataset
I am using Ubuntu 20.04. My collaborator is able to compile the make file on an older version of ubuntu with no problems. The only difference between her make file and mine is that I changed 'FC=gfortran' to 'FC=gfortran-9'. This is because gfortran no longer works on my version of Ubuntu, so I am using gfortran-9 as my compiler instead.
From reading other posts on here, it seems like it could be an issue with the flags that I'm using (i.e. the codes might have changed between the two fortran versions) but I've not been able to find any information on what flag to put in instead.
I am very new to programming, and any help would be appreciated!
I'm doing a socket project on win10, and I get these errors.
g++ -ggdb -std=c++11 -Wall -pedantic -o calcserver CalcServer.c
DieWithError.c HandleTCPClient.c CalcFramer.cpp CalcParser.cpp
C:\Users\HARRYS~1\AppData\Local\Temp\cceLC8Xb.o: In function `main':
D:\src/CalcServer.c:35: undefined reference to `__imp_socket'
D:\src/CalcServer.c:41: undefined reference to `__imp_htonl'
D:\src/CalcServer.c:42: undefined reference to `__imp_htons'
D:\src/CalcServer.c:45: undefined reference to `__imp_bind'
D:\src/CalcServer.c:49: undefined reference to `__imp_listen'
D:\src/CalcServer.c:58: undefined reference to `__imp_accept'
D:\src/CalcServer.c:64: undefined reference to `__imp_inet_ntoa'
collect2.exe: error: ld returned 1 exit status
make: *** [calcserver] Error 1
I tried to link Ws2_32.lib. I download Ws2_32.lib under directory src, and modify my makefile like this:
CC=g++
CFLAGS=-ggdb -std=c++11 -Wall -pedantic
LINKFLAGS = -L"D:\src" -lWS2_32
H_FILES=CalcFramer.hpp CalcParser.hpp
FILES=CalcServer.c DieWithError.c HandleTCPClient.c CalcFramer.cpp CalcParser.cpp
all: calcserver
calcserver: $(FILES) $(H_FILES)
$(CC) $(CFLAGS) -o calcserver $(FILES)
clean:
rm -rf calcserver
However, I still get the above errors. I've already changed all the sys/socket.h headers to Winsock.h and Winsock2.h. So I think it's not that part that leads me to the errors.
makefile:
lambda : main.o
gcc -o lambda main.o
main.o : main.c
gcc -c main.c -o main.o
.PHONY : clean
all I get as an answer instead of my executable is
main.o: In function `fn':
main.c:(.text+0x199): undefined reference to `pow'
main.c:(.text+0x1c6): undefined reference to `pow'
main.c:(.text+0x1eb): undefined reference to `log10'
main.o: In function `fnPrime':
main.c:(.text+0x21d): undefined reference to `pow'
main.c:(.text+0x246): undefined reference to `pow'
main.c:(.text+0x26b): undefined reference to `log10'
main.c:(.text+0x2af): undefined reference to `pow'
collect2: error: ld returned 1 exit status
make: *** [lambda] Error 1
what is wrong?
It looks like you're missing a reference to the Math library. You need to add -lm to the end of your make command
Well, after a search in stackoverflow I find that the problem was that I didn't put the option -lm at the end of the linking line.
lambda : main.o
gcc -o lambda main.o -lm
main.o : main.c
gcc -c main.c -o main.o
.PHONY : clean
clean : rm lambda main.o