Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22217

MYSYS2 mingw64 gcc can't link Shared Libary

$
0
0

Hail,

I'm attempting to link to a compiled shared library to main, and it tells me it cannot find the library - despite linking to a static library of the same name in a different folder having no issues. I am also able to make a shared library and link to it properly before trying to link to the library not in the current directory.

Perhaps I compiled it wrong or something, but here's the make files I used:

Makefile for external libraries:

all: objects libalpha.so libalpha.aobjects:    gcc -fPIC -c file1.c file2.c#shared liblibalpha.so: objects    gcc -shared -fPIC -Wl,-soname,C:\libs\libc\lib\shared\alpha.so -o C:\libs\libc\shared\libalpha.so file1.o file2.o#static liblibalpha.a: objects    ar rcs C:\libs\libc\static\libalpha.a file1.o file2.o

And here's the makefile for the main / internal libraries that do work before attempting to link to external libraries:

all: libtest libtwo libgroup.so libgroup.a main.o main_static main_sharedlibtest: ./sub/libtest.c ./sub/libtest.h    gcc -fPIC -c ./sub/libtest.c -o ./sub/libtest.olibtwo: ./sub/libtwo.c ./sub/libtwo.h    gcc -fPIC -c ./sub/libtwo.c -o ./sub/libtwo.o#shared - compiles and links properlylibgroup.so: ./sub/libtest.o ./sub/libtwo.o    gcc -shared -fPIC -Wl,-soname,./sub/libtest.o ./sub/libtwo.o -o ./sub/libgroup.so#static - compiles and links properlylibgroup.a: ./sub/libtest.o ./sub/libtwo.o    ar rcs ./sub/libgroup.a ./sub/libtest.o ./sub/libtwo.o#direct where the header files are locatedmain.o: main.c    gcc -IC:\libs\libc\CODE\alpha -c main.c#compiles fully and worksmain_static: main.o ./sub/libgroup.a    gcc main.o -L./sub -lgroup -LC:\libs\libc\static -lalpha -o main_static#doesn't work man??main_shared: main.o ./sub/libgroup.so    gcc main.o -L./sub -lgroup -LC:\libs\libc\shared -lalpha -o main_shared

And here's the error:

ld.exe: cannot find -lalphacollect2.exe: error: ld returned 1 exit statusmake: *** [makefile:27: main_shared] Error 1

And confirming they exist:

    Directory: C:\libs\libc\sharedMode                LastWriteTime         Length Name----                -------------         ------ -----a----         1/1/2022   4:19 AM         224820 libalpha.so    Directory: C:\libs\libc\staticMode                LastWriteTime         Length Name----                -------------         ------ -----a----         1/1/2022   4:19 AM           2324 libalpha.a

See anything obvious?

Thanks for your insight.


Viewing all articles
Browse latest Browse all 22217

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>