我不想使用 LD_LIBRARY_PATH,而是想通过-rpathmakefile 中的选项指定库搜索路径。我怎样才能做到这一点?假设搜索路径是当前目录。
			
			7130 次
		
3 回答
            3        
        
		
你有三个选择:
- 使用 LDFLAGS 指定选项 - ld
- 为编译和链接创建单独的规则,您可以 - -rpath=/what/ever直接- ld在此处parr
- 用于传播到链接器 - -Wl,ldoption。在你的情况下:- gcc- ldoption- gcc ... -Wl,rpath=/what/ever ...
请注意,LD_LIBRARY_PATH 为动态链接器/加载器 ( ldd) 服务,而不是为创建可执行文件 ( ld) 的链接器服务。
于 2012-12-11T13:28:52.143   回答
    
    
            1        
        
		
The -rpath flag needs to be passed to the linker. Prefix all flags with -Wl to have gcc pass them to ld, e.g.
LDFLAGS = -Wl,-rpath -Wl,.
于 2012-12-11T13:29:00.197   回答
    
    
            0        
        
		
例子
LDFLAGS += --rpath-link /home/hp/Desktop/staging_dir/target-mips_uClibc-0.9.30.1/root-brcmref/lib/ld-uClibc.so.0
生成文件示例:
all: test
%.o: %.c
    $(CC) $(CFLAGS) -c -o $@ $^
test: test1.o test2.o
    $(CC) $(LDFLAGS) -o $@ $^
于 2012-12-11T13:28:20.007   回答