0

I'm struggling really hard to make it work so I decided to look for help here.

I've written a program using Winsock2, for Windows, and no matter what I try, the library bundle that I create after compiling the objects seems to not be found (even testing my Makefile script with other program that compiles multiple sources) and there are all commands that I execute:

gcc -Isrc -c src/socketutils.c -o obj/socketutils.o
gcc -Isrc -c src/protocolutils.c -o obj/protocolutils.o
ar rcs lib/libacolytus.a obj/socketutils.o obj/protocolutils.o
gcc -c main.c -o obj/main.o -lwsock32 -lws2_32
gcc -shared -fPIC -o lib/libacolytus.so obj/socketutils.o obj/protocolutils.o -lwsock32 -lws2_32
gcc -o main main.c lib/libacolytus.so

But although everything runs fine, when I try to execute the main.exe the following error appears. What shall I do? (Windows 8.1 and MinGW GCC 7.3.0)

Error when I try to execute the compiled program

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
  • 1
    shouldn't windows be using dynamically linked libraries instead of shared objects? – Christian Gibbons Aug 01 '18 at 21:50
  • Are you sure `-fPIC` is valid for Windows? It looks like you're trying to mix Windows and Linux in the same application, and you can't do that; you need to compile everything for the appropriate target. – Ken White Aug 01 '18 at 22:10
  • @KenWhite not much, but it does not actually hurt to put it there too. –  Aug 01 '18 at 22:31
  • You ignored the most important part of my comment, which was not that first sentence. – Ken White Aug 01 '18 at 22:36
  • @ChristianGibbons I think that should be the case too, I will try look for it. –  Aug 01 '18 at 22:36
  • @KenWhite I did not ignore it, I actually answered it, using `-fPIC` under Windows is not valid but it do not break the entire command. –  Aug 01 '18 at 23:24
  • That's still not what I said. **Ignore that sentence.** Look at the **other sentence** in that comment. You can't mix Windows and Linux code, and .so (shared object) files are Linux files. WIndows uses a different technology that uses DLLs instead. – Ken White Aug 01 '18 at 23:58

0 Answers0