Miscellaneous Operating Systems/Hardware

AIX and getopt_long

i want to build goaccess https://goaccess.io on aix, but (of course) it gives me some troubles. i'm absolutely aware that getotp_long is not available in aix, so i decided to use net/freebsds implementation and copied over the two header files (getopt.h, cdefs.h).
unfortunatly the linker still chokes on undefined symbol getopt_long. how's that?

Code: Select all


root@aixbuildhost: /usr/local/src/goaccess/source/goaccess-1.2 # grep getopt_long /usr/include/getopt.h
* GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension.
int     getopt_long(int, char * const *, const char *,
int     getopt_long_only(int, char * const *, const char *,



snippet from the goaccess code using getopt_long (src/options.c)

Code: Select all


while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) {
if (-1 == o || EOF == o)
break;
switch (o) {
case 'f':
if (conf.filenames_idx < MAX_FILENAMES)
conf.filenames[conf.filenames_idx++] = optarg;
break;
case 'p':
/* ignore it */
break;



linker error

Code: Select all

root@aixbuildhost: /usr/local/src/goaccess/source/goaccess-1.2 # xlc_r -DSYSCONFDIR=\"/usr/local/goaccess/etc\" -q64 -qmaxmem=-1 -DNDEBUG -DSYSV -D_AIX -D_AIX64 -D_AIX41 -D_AIX43 -D_AIX51 -D_AIX52 -D_AIX53 -D_AIX61 -D_AIX71 -D_ALL_SOURCE -DFUNCPROTO=15 -I/opt/freeware/include  -L/opt/freeware/lib64 -L/opt/freeware/lib -Wl,-bmaxdata:0x80000000 -Wl,-b64 -Wl,-bexpall -Wl,-bnoipath -Wl,-brtl -o goaccess src/base64.o src/browsers.o src/color.o src/commons.o src/csv.o src/error.o src/gdashboard.o src/gdns.o src/gholder.o src/gmenu.o src/goaccess.o src/gslist.o src/gstorage.o src/gwsocket.o src/json.o src/opesys.o src/options.o src/output.o src/parser.o src/settings.o src/sha1.o src/sort.o src/ui.o src/util.o src/websocket.o src/xmalloc.o  src/gkhash.o    -lnsl -lncursesw -lpthread
ld: 0711-317 ERROR: Undefined symbol: .getopt_long

root@aixbuildhost: /usr/local/src/goaccess/source/goaccess-1.2 # xlc_r -DSYSCONFDIR=\"/usr/local/goaccess/etc\" -q64 -qmaxmem=-1 -DNDEBUG -DSYSV -D_AIX -D_AIX64 -D_AIX41 -D_AIX43 -D_AIX51 -D_AIX52 -D_AIX53 -D_AIX61 -D_AIX71 -D_ALL_SOURCE -DFUNCPROTO=15 -I/opt/freeware/include  -L/opt/freeware/lib64 -L/opt/freeware/lib -Wl,-bmaxdata:0x80000000 -Wl,-b64 -Wl,-bexpall -Wl,-bnoipath -Wl,-brtl -o goaccess src/base64.o src/browsers.o src/color.o src/commons.o src/csv.o src/error.o src/gdashboard.o src/gdns.o src/gholder.o src/gmenu.o src/goaccess.o src/gslist.o src/gstorage.o src/gwsocket.o src/json.o src/opesys.o src/options.o src/output.o src/parser.o src/settings.o src/sha1.o src/sort.o src/ui.o src/util.o src/websocket.o src/xmalloc.o  src/gkhash.o    -lnsl -lncursesw -lpthread -bnoquiet
(ld): setopt 64
(ld): halt 4
(ld): setopt expall
(ld): setopt noipath
(ld): setopt rtl
(ld): setopt rtllib
(ld): setopt symbolic:1
(ld): setfflag 4
(ld): savename goaccess
(ld): filelist 36 1
(ld): i /lib/crt0_64.o
(ld): i src/base64.o
(ld): i src/browsers.o
(ld): i src/color.o
(ld): i src/commons.o
(ld): i src/csv.o
(ld): i src/error.o
(ld): i src/gdashboard.o
(ld): i src/gdns.o
(ld): i src/gholder.o
(ld): i src/gmenu.o
(ld): i src/goaccess.o
(ld): i src/gslist.o
(ld): i src/gstorage.o
(ld): i src/gwsocket.o
(ld): i src/json.o
(ld): i src/opesys.o
(ld): i src/options.o
(ld): i src/output.o
(ld): i src/parser.o
(ld): i src/settings.o
(ld): i src/sha1.o
(ld): i src/sort.o
(ld): i src/ui.o
(ld): i src/util.o
(ld): i src/websocket.o
(ld): i src/xmalloc.o
(ld): i src/gkhash.o
(ld): lib /usr/lib/libnsl.a
(ld): lib /opt/freeware/lib/libncursesw.a
(ld): lib /usr/lib/libpthread.a
(ld): lib /opt/IBM/xlc/13.1.3/lib/libxlopt.a
(ld): lib /opt/IBM/xlc/13.1.3/lib/libxlipa.a
(ld): lib /opt/IBM/xlc/13.1.3/lib/libxl.a
(ld): lib /usr/lib/libc.a
(ld): lib /usr/lib/librtl.a
LIBRARY: Shared object libnsl.a[shr_64.o]: 430 symbols imported.
LIBRARY: Shared object libncursesw.a[libncursesw.so.5]: 598 symbols imported.
LIBRARY: Shared object libpthread.a[shr_xpg5_64.o]: 346 symbols imported.
LIBRARY: Shared object libc.a[shr_64.o]: 3096 symbols imported.
LIBRARY: Shared object libc.a[posix_aio_64.o]: 20 symbols imported.
LIBRARY: Shared object libc.a[aio_64.o]: 18 symbols imported.
LIBRARY: Shared object libc.a[pse_64.o]: 8 symbols imported.
LIBRARY: Shared object libc.a[dl_64.o]: 4 symbols imported.
LIBRARY: Shared object libc.a[pty_64.o]: 1 symbols imported.
LIBRARY: Shared object libc.a[cthread_64.o]: 25 symbols imported.
LIBRARY: Shared object libc.a[uchar_64.o]: 4 symbols imported.
LIBRARY: Shared object librtl.a[lazy42_64.o]: 3 symbols imported.
FILELIST: Number of previously inserted files processed: 36
(ld): resolve
RESOLVE: 1315 of 11565 symbols were kept.
(ld): addgl /usr/lib/glink64.o
ADDGL: Glink code added for 144 symbols.
(ld): er full
ld: 0711-318 ERROR: Undefined symbols were found.
The following symbols are in error:
Symbol                    Inpndx  TY CL Source-File(Object-File) OR Import-File{Shared-object}
RLD: Address  Section  Rld-type Referencing Symbol
----------------------------------------------------------------------------------------------
.getopt_long              [64]    ER PR src/options.c(src/options.o)
00000054 .text    R_RBR    [6]     .verify_global_config
00000110 .text    R_RBR    [6]     .verify_global_config
00000e68 .text    R_RBR    [16]    .read_option_args
00001110 .text    R_RBR    [16]    .read_option_args
ER: The return code is 8.


no plan
Next to the header files declaring getopt_long, you also need an implementation/definition of getopt_long, most commonly in a separate C-source file which you need to compile yourself (or a library with the symbol defined and implemented)

So you need https://github.com/freebsd/freebsd/blob ... opt_long.c and include that in the goaccess source, or build it separately as static or shared library and link with it.
:Crimson: :PI: :Indigo: :O2: :Indy: :Indigo2: :Indigo2IMP:
meanwhile i found a library which exports the missing symbol. this will suffice for testing the binary, will compile the getopt_long shared library as suggested by dexter1 later.


root@aixbuildhost: /usr/local/goaccess/bin # ldd goaccess
goaccess needs:
/usr/lib/libnsl.a(shr_64.o)
/opt/freeware/lib/libncursesw.a(libncursesw.so.5)
/usr/lib/libpthread.a(shr_xpg5_64.o)
/opt/freeware/lib/libmagic.a(libmagic.so.1)
/usr/lib/libc.a(shr_64.o)
/usr/lib/libthread.a(shr_64.o)
/usr/lib/libpthreads.a(shr_xpg5_64.o)
/usr/lib/libtli.a(shr_64.o)
/usr/lib/libC.a(shr3_64.o)
/usr/lib/libC.a(shr2_64.o)
/usr/lib/libc.a(shr.o)
/usr/lib/libpthreads.a(shr_xpg5.o)
/unix
/opt/freeware/lib64/libgcc_s.a(shr.o)
/opt/freeware/lib/libz.a(libz.so.1)
/usr/lib/libcrypt.a(shr_64.o)
/usr/lib/libc.a(pse_64.o)
/usr/lib/libC.a(shrcore_64.o)
/usr/lib/libcrypt.a(shr.o)
/usr/lib/libpthreads.a(shr_comm.o)
/usr/lib/libC.a(ansicore_64.o)

no plan