I'm porting what's primarily a very central (kind of like a libc extension) library from Linux to Cygwin and since I have a lot of setup and teardown and since I don't want to be using ctor/dtor attribute becaus of tcc compatibility, my library provides a main
function and the user is supposed to be using a "my_main" function that gets called by the main
function in the library.
It has worked very well on Linux but on Cygwin, I'm getting linker errors.
Here's an MCVE for building the library:
#!/bin/sh -eu
cat > libmain.c <<EOF
#include <stdio.h>
long my_main(int, char**);
int main(int C, char**V)
{
int r = 0;
puts("setup");
if(0>my_main(C,V))
r=-1;
puts("teardown");
return r;
}
EOF
gcc -shared -fpic -o libmain.so libmain.c -Wl,--allow-shlib-undefined
The above works on Linux, but on Cygwin, I'm getting:
/tmp/cc0s6qei.o:libmain.c:(.text+0x32): undefined reference to `my_main'
/tmp/cc0s6qei.o:libmain.c:(.text+0x32): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `my_main'
collect2: error: ld returned 1 exit status
Can this be made to work on Cygwin?