开发者

linking libaries and specifying path in makefile [duplicate]

This quest开发者_StackOverflow社区ion already has answers here: Closed 10 years ago.

Possible Duplicate:

Linking apache libraries

gcc 4.4.2 c89

I am trying to link some headers and libraries in my header file. But for some reason my program doesn't seem to link.

I have in my directory src/include/apr src/libs

I have compiled the libraries and placed them in my libs and I have put the headers in the include directory.

My executable is in the src directory.

In my makefile I have specified this:

LIBS_PATH -L./lib
INC_PATH -I./include

LIBS = -libapr-1

So the current directory to where the executable is executed from.

In my lib folder I have the following library called:

libapr-1.so

And in my include/apr folder I have the following header file:

apr.h

The program is getting the header files. But I don't think it is linking the library as I don't get any errors saying that it can't find the header file.

In the file where I include the header I have done this

#include <apr/apr.h>

I do get this following error message:

In file included from include/apr.h:17,                
./include/apr/apr.h:285: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘apr_int32_t’

Many thanks for any suggestions and advice,

EDIT:

LIBS_PATH -L./lib
INC_PATH -I./include

LIBS = -lapr

Error: /usr/bin/ld: cannot find -lapr

Makefile:

OBJECT_FILES = dlg_fsm.o 

CFLAGS = -ggdb -Wall 

FLATFORM = -DLINUX

CC = gcc

LIBS_PATH = -L./lib
INC_PATH = -I./include

LIBS = -lapr

dlg: $(OBJECT_FILES)
    $(CC) $(CFLAGS) $(LDFLAGS) $(OBJECT_FILES) $(FLATFORM) $(INC_PATH) $(LIBS_PATH) $(LIBS) -o dlg


This has nothing to do with libraries, and may have nothing to do with paths. The compiler thinks there is a syntax error at the line indicated - please post that line, and the ones surrounding it, using copy and paste.


Once you've fixed the syntax error in your code, you'll want to change LIBS to contain -lapr-1, since the linker adds the "lib" prefix itself.


Either there is a syntax error in apr.h or probably apr.h expects something to be included before itself.

For example:

you write header file abc.h which uses strlen(...), but do not include string.h inside abc.h . If you want to include abc.h in file xxx.c, you have to include string.h in xxx.c before abc.h manually to make sure that abc.h has access to the declaration of strlen(...)


Most likely the compiler doesn't know what apr_int32_t means, whereas it should. You should post line 285 of apr.h.

Edit: I think when you say:

And in my include/apr folder I have the following header file: apr.h

that might be what's wrong. You should not have an apr.h file in your local directory—it's a file from APR. So, try renaming the file include/apr/apr.h to something else (unless by include/apr you meant your system include directory).

Edit 2:

LIBS_PATH -L./lib
INC_PATH -I./include

From the above, looks like you're in the apr source directory. Please install apr by typing make install in the apr directory, and then use the installed files in /usr/include/apr and /usr/lib/libapr* to build your program. You should not have your local source and include directories in the apr directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜