« Back to Technical Questions

Event API C++ Program compilation problems

Combination View Flat View Tree View
Hi all, I have been testing Event API in Java successfully, but now I have moved to C++ at first I was unable to compile C++ IOS API program, but I found on this forum a guy solved with this method:
 
g++ -c -Wall appretest.cpp -o appretest.o
g++ -g -Wall -o appretest appretest.o -L. -lappreapi -lm

 
The key was "-lappreapi" to load the .h file, I used this with iosapi.cpp program and appreapi.cpp program successfully, but when I tried to compile your Event API example I got this error:
 
eventapi.o: In function 'main':
eventapi.cpp.text+0x4a): undefined reference to 'getNotifyRequest(char const*, NotifyRequest**)'
eventapi.cpp.text+0x66): undefined reference to 'PolicyInfo_new(char const*, char const*, char const*)'
eventapi.cpp.text+0x12f): undefined reference to 'PolicyInfo_new(char const*, char const*, char const*)'
eventapi.cpp.text+0x234): undefined reference to 'PolicyInfo_new(char const*, char const*, char const*)'
eventapi.cpp.text+0x30d): undefined reference to 'PolicyInfo_new(char const*, char const*, char const*)'
collect2: ld returned 1 exit status
 
I have tried to complie with several -l options to load .h files but I don´t know which option I have to use.
g++ -c -Wall eventapi.cpp -o eventapi.o
g++ -g -Wall -o eventapi eventapi.o -L. -liosapi -lappreapi -leventapi -laxpsystemapi -lutilserviceapi -lm -ldl
 
Any idea??
 
Thanks in advance..
 
Alejandro Rico

Hi,
 
I think you will need to use the -I, -L, and -l flags when compiling using the Event API.  An explanation of what these do is below:
 
    -I : Specify your "Include" directory.  This is a directory that has all header (.h) files.
    -L : Specify your library directory.  This is a directory that includes all library (.so) files.
    -l  : Specify the libraries to include.

For the event api, your .cpp file will need to inculde AxpServiceAPI.h.
 
    #include "AxpServiceAPI.h"
 
To compile, you will need to specify the following arguments:
 
    -I<SDK directory>/include -L<SDK directory>/lib -leventapi -lxerces-c
 
Assume your axp-sdk directory is named "/axp/sdk" and you want to name this executable program "myeventapi."  So, your final commands will look something like like this:

1
2    ## Compile step
3    g++ -I/axp/sdk/include -Wall -c -omyeventapi.o eventapi.cpp
4    ## Link step
5    g++ -L/axp/sdk/lib -omyeventapi myeventapi.o -leventapi -lxerces-c -ldl



Hope this helps,
 
-Carl

Hi Carl, thank you very much, seems that I was missing some steps in compilation, but unfortunately I am still having the same problems..
 
I have used this sentence as you suggest me:
 
g++ -I/source/axp-sdk.1.6.1/include/ -Wall -c eventapi.cpp -o eventapi.o
g++ -L/source/axp-sdk.1.6.1/lib/ -Wall -o eventapi eventapi.o -leventapi -liosapi -lappreapi -lxerces-c -ldl
 
And the erros are the same as before..
 
eventapi.o: In function 'main':
eventapi.cpp(.text+0x4a): undefined reference to 'getNotifyRequest(char const*, NotifyRequest**)'
eventapi.cpp(.text+0x66): undefined reference to 'PolicyInfo_new(char const*, char const*, char const*)'
eventapi.cpp(.text+0x12f): undefined reference to 'PolicyInfo_new(char const*, char const*, char const*)'
eventapi.cpp(.text+0x234): undefined reference to 'PolicyInfo_new(char const*, char const*, char const*)'
eventapi.cpp(.text+0x30d): undefined reference to 'PolicyInfo_new(char const*, char const*, char const*)'
collect2: ld returned 1 exit status
 
The code of eventapi.cpp it is the same I found at AXP Developer Guide.
 
Any suggestion?
 
Thanks,
 
Alejandro Rico

Hi Alejandro,
 
It turns out that the issue is in the SDK.  In the interest of moving forward, I've attached a new AxpServiceAPI.h file for you to use.  Please download this file into your <AXP-SDK>/include directory.
 
I was able to successfully compile the program using the following lines:

1
2> g++ -I<AXP_SDK>/include -Wall -c eventapi.cpp -oeventapi.o
3> g++ -L<AXP_SDK>/lib -Wall -o eventapi eventapi.o -lxerces-c -lappreapi -leventapi

 
FYI, the fix was to use extern "C" instead of extern in the header file.  This is an issue with C++ compilers.  To fix the issue, I added the following:

 1
 2#ifndef _AXP_SERVICE_API_H_
 3#define _AXP_SERVICE_API_H_
 4 
 5// Begin additional lines
 6#ifdef __cplusplus
 7extern "C" {
 8#endif
 9// End additional lines
10
11...
12 
13// Begin additional lines
14#ifdef __cplusplus
15}
16#endif
17// End additional lines
18
19#endif  /* _AXP_SERVICE_API_H_ */

 
Please let me know if this works for you.  Thanks,
 
-Carl
Attachments:

Hi Carl, thank you very much, finally works!! I think the problem is the header file...
 
Thanks,
 
Alejandro