How to specify RPATH in a makefile?

前端 未结 1 873
灰色年华
灰色年华 2020-12-23 23:14

I\'m trying to specify rpath in my binary. My makefile looks like this-

CC=gcc 
CFLAGS=-Wall
LDFLAGS= -rpath=\'../libs/\'
main: main.c  
    gcc -o main ma         


        
相关标签:
1条回答
  • 2020-12-23 23:33

    If you set the variables, you should probably use them. It's silly not to, especially when make won't magically set those variables for you! :)

    main: main.c
        $(CC) $(CFLAGS) $(LDFLAGS) -o main main.c
    

    Another problem is LDFLAGS, it should be

    LDFLAGS="-Wl,-rpath,../libs/"
    

    The usual gcc switch for passing options to linker is -Wl,, and it is needed because gcc itself may not understand the bare -rpath linker option. While some builds of various versions of gcc accept -rpath, I have never seen it documented in gcc man pages or info pages. For better portability, -Wl,-rpath should be preferred.

    0 讨论(0)
提交回复
热议问题