0

I made a TCP socket program in C++ that uses wsock32 and openssl, but I want to link openssl static.

I have compiled openssl on mingw32 with shared and no-shared but I keep getting the same undefined reference errors.

It builds fine if I link the .a.dll instead of .a but I don't want to use dll's.

Here's how I compile:

/c/MinGW/bin/mingw32-g++.exe main.cpp -I /c/Mingw-builds/openssl/include -L/c/MinGW/lib -L /c/Mingw-builds/openssl/lib -std=c++11 -lwsock32 -lshlwapi -lws2_32 -lssl -lcrypto -lgdi32

Errors that I get:

C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xac): undefined reference to `getnameinfo@28'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0x6ef): undefined reference to `freeaddrinfo@4'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_addr.o):b_addr.c:(.text+0xa28): undefined reference to `getaddrinfo@16'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0xe6): undefined reference to `WSAGetLastError@0'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x2d6): undefined reference to `WSAGetLastError@0'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x40b): undefined reference to `getsockopt@20'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x43b): undefined reference to `gethostbyname@4'
C:/Mingw-builds/openssl/lib/libcrypto.a(b_sock.o):b_sock.c:(.text+0x4a0): undefined reference to `WSAGetLastError@0'
scott_lotus
  • 3,171
  • 22
  • 51
  • 69
John Doe
  • 21
  • 6

1 Answers1

0

Nvm got it working by ordering it right:

/c/MinGW/bin/mingw32-g++.exe main.cpp -o asdf.o -I /c/Mingw-builds/openssl/include -L /c/Mingw-builds/openssl/lib -std=c++11 -lmingw32 -lssl -lcrypto -luser32 -lgdi32 -lws2_32 -lwsock32 -lshlwapi -static-libgcc -static-libstdc++ -shared
Holt
  • 36,600
  • 7
  • 92
  • 139
John Doe
  • 21
  • 6
  • See http://stackoverflow.com/questions/3363398/g-linking-order-dependency-when-linking-c-code-to-c-code. – Holt Apr 24 '16 at 08:13