我正在爲Mac OS X(10.7.1)上的C++構建google-gflags命令行標誌庫。構建過程是這樣:如何在構建時修改.dylib的安裝名稱
$ ./configure --prefix=output
$ make
$ make install
我想在構建時改變產生的共享庫的安裝名稱,而不是使用install_name_tool
之後。
默認情況下,生成的共享庫,libgflags.dylib
的install name,是輸出路徑:
$ otool -L ./output/libgflags.dylib
$ ./output/libgflags.dylib:
/tmp/gflags-1.5/output/lib/libgflags.0.dylib (compatibility version 2.0.0, current version 2.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)
爲ld(1)
手冊頁有一個-install_name
選項,它可以用來更改安裝一個動態的名字圖書館在鏈接時。
例如,虛擬程序:
$ g++ -dynamiclib temp.cc -install_name /tmp/temp.dylib -o temp.dylib
$ otool -L temp.dylib
temp.dylib:
/tmp/temp.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)
但是,我無法使用與./configure
腳本此命令行選項。我已經試過手動設置CFLAGS
變量,但導致一個錯誤:
$ CFLAGS="-install_name /tmp/desired/location/libgflags.dylib" ./configure
checking for a BSD-compatible install... /opt/local/bin/ginstall -c
checking whether build environment is sane... yes
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/Users/vibhav/Code/install_name_test/gflags-1.5':
configure: error: C compiler cannot create executables
那麼,是不是我能夠改變由configure
和make
生成名爲.dylib的安裝名稱,而不使用install_name_tool
?
我不明白你在做什麼。爲什麼不能簡單地運行'./configure --prefix/tmp/desired/location'? – adl
這是一個有效的問題。我不能將'--prefix'設置爲該位置出於各種原因,包括我的構建位置與我的應用程序的「安裝」位置不同。我只是想在使用configure時傳遞適當的鏈接器標誌。 – v8891
你的情況對我來說還不清楚。你能否解釋標準的'./configure --prefix/somewhere && make && make install'對於你的設置是錯誤的?爲什麼你的構建位置很重要? (當然,您應該使用絕對前綴。)您是否嘗試鏈接到'libglflags'而不安裝它? (在這種情況下,您應該使用'libtool'將您的應用程序與'libflag.la'鏈接起來,並讓libtool發揮它的魔力,以便與未安裝的庫鏈接。)是否要在安裝庫之前將它安裝到臨時位置複製到其最終位置? (這是DESTDIR變量的一項工作。) – adl