About build static library

  • Thread starter =?gb2312?B?wfXquw==?=
  • Start date
?

=?gb2312?B?wfXquw==?=

Hi, folks,
I've googled for the forum focusing on how to write the makefile,
nothing found. So I'd like to ask you guys do me a favor. I am
building a static library under Msys and MinGW, I've found all the
source files I need, and put them into one folder, my makefile looks
like:

CC=g++
CCFLAGS=-w -g

AR=ar
ARFLAGS=cruv

LIBOBJS = a.o
LIBHEADER=

LIBNAME = libtest.a

a.o: *.cpp *.h
$(CC) $(CCFLAGS) -c -o a.o a.cpp

all: $(LIBOBJS)
$(AR) $(ARFLAGS) $(LIBNAME) $(LIBOBJS)
cp $(LIBNAME) $(HOME)/source/openct/sdk/lib
cp $(LIBNAME) /usr/local/lib

clean:
-rm $(LIBOBJS) libtest.a

But when I built the program that linked this lib, a link error
araised, complained that some functions undefined, but the source
files contain the declaration and implementation, thank you.

Best regards.
 
G

Gianni Mariani

Áõê» said:
Hi, folks,
I've googled for the forum focusing on how to write the makefile,
nothing found. So I'd like to ask you guys do me a favor. I am
building a static library under Msys and MinGW, I've found all the
source files I need, and put them into one folder, my makefile looks
like:

Makefiles are more on-topic in comp.programmer.unix

Also, show the code that creates the problem. Which is your error -
what is the command that caused the error to be displayed.
 
J

Jorgen Grahn

Hi, folks,
I've googled for the forum focusing on how to write the makefile,
nothing found. So I'd like to ask you guys do me a favor. I am
building a static library under Msys and MinGW, I've found all the
source files I need, and put them into one folder, my makefile looks
like:

CC=g++
CCFLAGS=-w -g

Do yourself a favor and add more strictness flags above. You may also
want to call them "CXX" and "CXXFLAGS", if your make program behaves
like Gnu make, and knows these names refer to C++ compilation.

Reading the g++ documentation, "-w" seems to mean "disable all
warnings". That seems like a highly unusual thing to do -- especially
when debugging a strange problem.
But when I built the program that linked this lib, a link error
araised, complained that some functions undefined, but the source
files contain the declaration and implementation, thank you.

Then go to the object files. You should have a tool for listing names
in object files and static libraries (on Unix, it's often "nm -C file").

Also remember that order matters to many linkers:

link a.obj b.lib c.obj d.lib

will only pull in symbols from b.lib if a.obj needed them. It doesn't
care what symbols c.obj and d.lib needs.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top