user1479589
user1479589

Reputation: 315

undefined reference on linux but works fine on mac

I am trying to execute the following:

gcc -Ilibconfig controller.c -o Controller libconfig/libconfig.a

but what I get is:

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

Now I can understand that the linker is failing to link the library,however I have made sure that the library comes after the files and this works just fine on OSX, I have no idea why this is happening.

Please if anybody could help out.

Thanks

Upvotes: 3

Views: 1288

Answers (1)

Sergey L.
Sergey L.

Reputation: 22542

You should be linking the libraryas a library, not as object code.

gcc -Ilibconfig controller.c -o Controller -Llibconfig -lconfig

Linux and OS X use completely different linkers, so they may behave differently in the kind of files they accept.

Upvotes: 2

Related Questions