今天在 ubuntu 中了招,Makefile 中這樣寫:
1 2 |
; html-script: false ] g++ -Wall -lcrypto $^ -o $@ |
結果一直顯示錯誤:
1 2 3 4 |
; html-script: false ] undefined reference to `ERR_load_crypto_strings' undefined reference to `OPENSSL_add_all_algorithms_noconf' undefined reference to `OPENSSL_config' |
檢查了 libssl-dev 有安裝,也跑去 /usr/lib 建立一些 link,但是問題都沒有解決。
最後原因是這個:
The –as-needed option also makes the linker sensitive to the ordering of libraries on the command-line. You may need to move some libraries later in the command-line, so they come after other libraries or files that require symbols from them.
Ubuntu 自 11.04 後,預設會將 –as-needed 選項打開,所以參數的順序突然變得很重要了,改成這樣就可以了:
1 2 |
; html-script: false ] g++ $^ -o $@ -Wall -lcrypto |
參考資料:
https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition