我試圖執行以下操作:未定義參考,但能正常工作在Mac
gcc -Ilibconfig controller.c -o Controller libconfig/libconfig.a
但我得到的是:
In function `processConfigFile':
controller.c:(.text+0x10e): undefined reference to `config_init'
controller.c:(.text+0x132): undefined reference to `config_read_file'
controller.c:(.text+0x169): undefined reference to `config_destroy'
controller.c:(.text+0x188): undefined reference to `config_lookup_string'
controller.c:(.text+0x1e0): undefined reference to `config_lookup_string'
controller.c:(.text+0x269): undefined reference to `config_lookup_string'
controller.c:(.text+0x2cc): undefined reference to `config_lookup_string'
controller.c:(.text+0x317): undefined reference to `config_lookup_string'
controller.c:(.text+0x36e): undefined reference to `config_lookup'
controller.c:(.text+0x403): undefined reference to `config_setting_length'
controller.c:(.text+0x454): undefined reference to `config_setting_get_string_elem'
controller.c:(.text+0x4fa): undefined reference to `config_destroy'
collect2: error: ld returned 1 exit status
現在,我可以理解,鏈接器未能鏈接庫,但是我已經確定該庫是在文件之後出現的,這在OSX上工作得很好,我不知道爲什麼會發生這種情況。
請有人幫忙。
謝謝
切換命令行參數的順序是否有幫助?即調用'gcc -Ilibconfig -o Controller libconfig/libconfig.a controller.c' – scai
在Linux系統上從頭開始重建'libconfig/libconfig.a'?嘗試將OSX庫鏈接到Linux可執行文件可能會有點不可靠... – twalberg