Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespace to getopt functions #134

Closed
wants to merge 1 commit into from

Conversation

luispedro
Copy link

This enables static linking. Otherwise, these functions conflict with the standard getopt functions.

This enables static linking. Otherwise, these functions conflict with
the standard getopt functions.
@lh3
Copy link
Owner

lh3 commented Mar 19, 2018

If your system has getopt, then you should use the system getopt for static linking. I have made main.c optionally use system getopt by defining HAVE_GETOPT. For static linking, use the following:

gcc -g -Wall -O2 -Wc++-compat -DHAVE_GETOPT main.c -o minimap2 -L. -lminimap2 -lm -lz -lpthread -static

@lh3 lh3 closed this Mar 19, 2018
@luispedro
Copy link
Author

Thanks. This is a better solution to the problem than my patch.

luispedro added a commit to ngless-toolkit/ngless that referenced this pull request Jul 17, 2018
@unode
Copy link

unode commented Sep 17, 2018

@lh3 on CentOS 6.6 and using rel v2.12 running:

make CFLAGS="-O2 -DHAVE_GETOPT -static"
(...)
cc -c -O2 -DHAVE_GETOPT -static -msse2 -mno-sse4.1 -DHAVE_KALLOC -DKSW_CPU_DISPATCH -DKSW_SSE2_ONLY  ksw2_exts2_sse.c -o ksw2_exts2_sse2.o
cc -c -O2 -DHAVE_GETOPT -static -msse4.1 -DHAVE_KALLOC -DKSW_CPU_DISPATCH  ksw2_dispatch.c -o ksw2_dispatch.o
ar -csru libminimap2.a kthread.o kalloc.o misc.o bseq.o sketch.o sdust.o options.o index.o chain.o align.o hit.o map.o format.o pe.o esterr.o splitidx.o ksw2_ll_sse.o ksw2_extz2_sse41.o ksw2_extd2_sse41.o ksw2_exts2_sse41.o ksw2_extz2_sse2.o ksw2_extd2_sse2.o ksw2_exts2_sse2.o ksw2_dispatch.o
cc -O2 -DHAVE_GETOPT -static main.o getopt.o -o minimap2 -L. -lminimap2 -lm -lz -lpthread
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libc.a(getopt.o):(.data+0x0): multiple definition of `optind'
getopt.o:(.data+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libc.a(getopt.o):(.data+0x4): multiple definition of `opterr'
getopt.o:(.data+0x4): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libc.a(getopt.o): In function `getopt':
(.text+0x1560): multiple definition of `getopt'
getopt.o:getopt.c:(.text+0xb0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libpthread.a(libpthread.o): In function `sem_open':
(.text+0x77cd): warning: the use of `mktemp' is dangerous, better use `mkstemp'
collect2: ld returned 1 exit status
make[1]: *** [minimap2] Error 1

still failed linking. Having -DHAVE_GETOPT was insufficient.

Running the gcc command listed above worked around the problem but that command explicitly doesn't include getopt.o.

Any chance of also having this fixed in the makefile?

@lh3
Copy link
Owner

lh3 commented Sep 17, 2018

The github HEAD uses a different command-line argument parser, which is functionally equivalent to getopt. It won't have this issue any more.

luispedro added a commit to ngless-toolkit/ngless that referenced this pull request Nov 20, 2018
Static building of 2.9 was impossible due to the issue in
lh3/minimap2#134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants