Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 views
in Technique[技术] by (71.8m points)

c - Linking against a static library

gcc Version: 4:4.4.4-1ubuntu2 GNU Make 3.81

I have the following library called net_api.a and some header files i.e.

network_set.h

I have include the header file in my source code in my main.c file

#include <network_set.h>

I have the following static library and header in the following directory

./tools/net/lib/net_api.a
./tools/net/inc/network_set.h

In my Makefile I have tried to link using the following, code snippet:

INC_PATH = -I tools/net/inc
LIB_PATH = -L tools/net/lib

LIBS = -lnet_api

$(TARGET): $(OBJECT_FILES)
    $(CC) $(LDFLAGS) $(CFLAGS) $(INC_PATH) $(LIB_PATH) $(LIBS) $(OBJECT_FILES) -o $(TARGET)

main.o: main.c
    $(CC) $(CFLAGS) $(INC_PATH) $(LIB_PATH) -c main.c

However, when I compile I get the following errors:

network_set.h error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘network_String’

What is going wrong here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The header network_set.h has extra dependencies that must be included first, one of which is the definition of network_String. Check the library documentation or consult the author for more details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...