adobkin / libcapn

A simple C Library for interact with the Apple Push Notification Service (APNs)
MIT License
100 stars 37 forks source link

undefined reference to `apn_init' ON Ubuntue #14

Closed gfxcc closed 8 years ago

gfxcc commented 9 years ago

This lib can run on my Mac OS 10.10 But when I test same code on Ubuntu, It goes wrong. I followed steps http://libcapn.org/doc/0.9.0/html/install.html I have spend all my night on this.

$ gcc /usr/local/lib/capn/libcapn.so t.c
/tmp/ccO1OvrG.o: In function `main':
t.c:(.text+0x65): undefined reference to `apn_init'
t.c:(.text+0x75): undefined reference to `apn_error_code'
t.c:(.text+0x88): undefined reference to `apn_error_message'
t.c:(.text+0xa8): undefined reference to `apn_error_free'
t.c:(.text+0xc8): undefined reference to `apn_set_mode'
t.c:(.text+0xe0): undefined reference to `apn_add_token'
t.c:(.text+0xf3): undefined reference to `apn_payload_init'
t.c:(.text+0x103): undefined reference to `apn_error_code'
t.c:(.text+0x116): undefined reference to `apn_error_message'
t.c:(.text+0x136): undefined reference to `apn_free'
t.c:(.text+0x142): undefined reference to `apn_error_free'
t.c:(.text+0x16e): undefined reference to `apn_payload_set_badge'
t.c:(.text+0x186): undefined reference to `apn_payload_set_body'
t.c:(.text+0x1a3): undefined reference to `apn_payload_set_expiry'
t.c:(.text+0x1b9): undefined reference to `apn_payload_set_sound'
t.c:(.text+0x1d4): undefined reference to `apn_payload_add_custom_property_integer'
t.c:(.text+0x1e7): undefined reference to `apn_connect'
t.c:(.text+0x1f7): undefined reference to `apn_error_code'
t.c:(.text+0x20a): undefined reference to `apn_error_message'
t.c:(.text+0x22a): undefined reference to `apn_payload_free'
t.c:(.text+0x236): undefined reference to `apn_free'
t.c:(.text+0x242): undefined reference to `apn_error_free'
t.c:(.text+0x263): undefined reference to `apn_send'
t.c:(.text+0x277): undefined reference to `apn_error_code'
t.c:(.text+0x28a): undefined reference to `apn_error_message'
t.c:(.text+0x2aa): undefined reference to `apn_error_code'
t.c:(.text+0x2c0): undefined reference to `apn_error_invalid_token'
t.c:(.text+0x2de): undefined reference to `apn_close'
t.c:(.text+0x2ea): undefined reference to `apn_payload_free'
t.c:(.text+0x2f6): undefined reference to `apn_free'
t.c:(.text+0x302): undefined reference to `apn_error_free'
t.c:(.text+0x315): undefined reference to `apn_close'
t.c:(.text+0x321): undefined reference to `apn_payload_free'
t.c:(.text+0x32d): undefined reference to `apn_free'
collect2: error: ld returned 1 exit status
gfxcc commented 9 years ago

t.c is http://libcapn.org/doc/html/send_push_8c-example.html

adobkin commented 9 years ago

You specified incorrect path to lib. Shall be:

$ gcc -lcapn -L /usr/local/lib/capn t.c

gfxcc commented 9 years ago

I tried your command. It show the same error like mine. I do not think the lib path is incorrect. I install capn on my mac os X like ---$brew install libcapn And i can compile on mac like ------$gcc /usr/local/lib/capn/libcapn.dylib t.c

Help me out~~ Thanks

adobkin commented 9 years ago

It's my error in command, try:

$ gcc t.c -lcapn -L /usr/local/lib/capn

gfxcc commented 9 years ago

New command works !!! Thank you. But I meet a new Problem

At begin ./a.out ./a.out: error while loading shared libraries: libcapn.so.1: cannot open shared object file: No such file or directory I run $ldconfig and problem solved. No error printed. But my iPhone does not receive notification.

With the same code on Mac os X, my iPhone can receive notification. I can sure the token is correct and PEM is fight. (cause if I change path for .pem. It will show error message like ----Could not connected to Apple Push Notification Servece: unable to use specified SSL certificate (12))

How to solve this problem? Thanks very much!

adobkin commented 9 years ago

Without seeing a code it is very difficult to speak about a possible problem. The current version also doesn't support logging. I would recommend to you to try version 2.0.0, it support logging and working faster. Look it https://github.com/adobkin/libcapn/tree/experimental. This branch is EXPERIMENTAL and it not compatible to 1.0. Experimental branch will be merged with master soon

gfxcc commented 9 years ago

I remove /usr/local/lib/capn/* /usr/local/include/capn/*

installd version 2.0.0 copy your simple code. something like this happened ubuntu@ip-172-31-17-20:~/libcapn/test$ gcc t.c -lcapn -L /usr/lib/capn t.c: In function ‘main’: t.c:18:9: error: variable ‘payload’ has initializer but incomplete type apn_payload_t payload = NULL; ^ t.c:18:23: error: storage size of ‘payload’ isn’t known apn_payload_t payload = NULL; ^ t.c:19:9: error: variable ‘ctx’ has initializer but incomplete type apn_ctx_t ctx = NULL; ^ t.c:19:19: error: storage size of ‘ctx’ isn’t known apn_ctx_t ctx = NULL; ^ t.c:52:9: error: variable ‘tokens’ has initializer but incomplete type apn_array_t tokens = apn_array_init(2, NULL, NULL); ^ t.c:52:21: error: storage size of ‘tokens’ isn’t known apn_array_t tokens = apn_array_init(2, NULL, NULL); ^

adobkin commented 9 years ago

In example I lost asterisks. I fixed it and I added example tohttps://github.com/adobkin/libcapn/tree/experimental/examples. Try it

gfxcc commented 9 years ago

$$$$~/libcapn/libcapn/examples$ gcc send_push_message.c -lcapn -L/usr/lib/capn send_push_message.c: In function ‘main’: send_push_message.c:74:41: error: ‘APN_ARRAY_ITERATOR_REVERSE’ undeclared (first use in this function) for(apn_array_set_direction(tokens, APN_ARRAY_ITERATOR_REVERSE); apn_array_has_prev(tokens) == 1; apn_array_prev(tokens)) { ^ send_push_message.c:74:41: note: each undeclared identifier is reported only once for each function it appears in send_push_message.c:75:23: warning: initialization makes pointer from integer without a cast [enabled by default] char *token = apn_array_current_item(tokens); ^

adobkin commented 9 years ago

send_push_message.c:74:41: error: ‘APN_ARRAY_ITERATOR_REVERSE’ undeclared (first use in this

fixed

gfxcc commented 9 years ago

Success! Segmentation fault (core dumped)

did send the notification. Thanks~ Looking forward to your libcapn2