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

Crosscompile linux to windows: linking fails, undefined reference SSL_library_init 3.9.2 #1053

Open
tillpp opened this issue May 12, 2024 · 4 comments

Comments

@tillpp
Copy link

tillpp commented May 12, 2024

I compiled it for windows using linux with the README.windows commands
i got three library files, tls.a,ssl.a and crypto.a
but when i tried using them i got the following error message:

/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/_.dir/objects.a(main.cpp.obj):_/src/main.cpp:5: undefined reference to `SSL_load_error_strings'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/_.dir/objects.a(main.cpp.obj): in function `main':
_/src/main.cpp:6: undefined reference to `SSL_library_init'

but everything works well when compiling with just gcc on linux for linux, the error only occurs when crosscompiling

@busterb
Copy link
Contributor

busterb commented May 28, 2024

Can you please say more about what commands you used to build your main.cpp file, and its contents?

@busterb
Copy link
Contributor

busterb commented May 28, 2024

Here's a quick working example for you to play with:

$ make install DESTDIR=`pwd`/install > /dev/null
libtool: warning: remember to run 'libtool --finish /usr/local/lib'
libtool: warning: remember to run 'libtool --finish /usr/local/lib'
libtool: warning: remember to run 'libtool --finish /usr/local/lib'
$ cat main.cpp 
#include <openssl/ssl.h>

int main(int argc, char const *argv[])
{
	printf("SSL_library_init returned %d\n", SSL_library_init());
}
$ x86_64-w64-mingw32-c++ main.cpp -Iinstall/usr/local/include -Linstall/usr/local/lib -lssl -lcrypto -lws2_32 -lbcrypt -static
$ wine ./a.exe
SSL_library_init returned 1

Keep in mind you should install the library somewhere (implied, but not explicitly spelled out in the README) in order to use it, and you'll also need to explicitly link in some support libraries on Windows that are implicit on other platforms. I think the linker script should help you automatically here, but if you're cross-compiling straight from the command line, you're probably not using it.

Hope this helps!

@busterb
Copy link
Contributor

busterb commented May 28, 2024

@RandomInEqualities do you think this needs more clarification in the docs, or is something like this fairly clear when folks are targeting Windows already?

@RandomInEqualities
Copy link
Contributor

I think if using CMake this is all handled by that, so nothing is needed there! I'm not sure about cross compiling, since that does require the extra -lws2_32 and installing the library. Maybe it could be mentioned in an additional section about cross-compiling (but mind I don't cross compile myself, so I don't know too much about it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants