Statically cross compiling openssl on linux for windows - c

I'm trying to compile an app with static openssl. I compiled openssl with mingw options and now my lib directory has: libcrypto.a libssl.a libcrypto.dll.a libssl.dll.a
I used the correct -L compiler options and still I get these errors:
x86_64-w64-mingw32-gcc main.c -lws2_32 -s -ffunction-sections -fdata-sections -Wno-write-strings -fno-exceptions -fmerge-all-constants -static-libstdc++ -static-libgcc -static -L/rw/usrlocal/lib/ -I/rw/usrlocal/include/ -lssl -lcrypto
~~~~~~~~^~~~~
/usr/bin/x86_64-w64-mingw32-ld: skipping incompatible /rw/usrlocal/lib//libssl.a when searching for -lssl
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lssl
/usr/bin/x86_64-w64-mingw32-ld: skipping incompatible /rw/usrlocal/lib//libcrypto.a when searching for -lcrypto
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
Can someone here tell me why mingw is using the libcrypto.a and not libcrypto.dll.a? And what's more important: How I can change that?
Greetings

It literally says "skipping incompatible", which leads me to think the libraries are not targetting the same platform. Are you sure you're not mixing 32-bit and 64-bit Windows?
Run the file command with the .dll file of openssl to see if they are also targetting x86_64.
When building openssl you should specify mingw64 with the ./Configure command.

Related

Static link SDL2 on Linux

I am trying to statically link SDL2 on Linux, with the goal of creating a binary that doesn't require any libraries to be required on the system. I understand this will require statically linking more than just SDL2, such as SDL2's dependencies and things like libc, so help on that front would be appreciated as well. But right now I can't get SDL2 to statically link at all.
I am using GCC, and SDL 2.0.16 that I compiled and installed myself with the default configuration, which includes static libraries. I already had SDL2 installed through my package manager, so my installation went to /usr/local/include/SDL2 and /usr/local/lib.
Running /usr/local/bin/sdl2-config --cflags --static-libs gives:
-I/usr/local/include/SDL2 -D_REENTRANT
-L/usr/local/lib -lSDL2 -lm -ldl -lpthread -lrt
No amount of messing around with these flags and -static have been able to produce a binary that doesn't dynamically link to SDL2. How can I do it?
Other flags I am using for other reasons are -std=c89 -Wall -Wno-unknown-pragmas -DNDEBUG -Os -g0 -s
Being able to cross compile and do this would be great, but I understand that's a lot more complex. I've been trying to compile with zig cc as that would allow cross-compilation later, but couldn't get it to work. I was able to get a build that didn't dynamically link to SDL2, but it would segfault.
In response to comments:
Running pkg-config --static --cflags --libs /usr/local/lib/pkgconfig/sdl2.pc gives:
-I/usr/local/include/SDL2 -D_REENTRANT -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2 -lm -ldl -lpthread -lrt
Using that creates a dynamically-linked executable, so not what I want. If I add -static I get the error:
/usr/bin/ld: /usr/local/lib/libSDL2.a(SDL_dynapi.o): in function `get_sdlapi_entry':
/home/makeworld/Software/SDL2-2.0.16/src/dynapi/SDL_dynapi.c:237: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Thanks to #HolyBlackCat and #keltar, I have been able to statically link SDL2.
I basically just used the output of pkg-config as provided in my question, but with the addition of -Wl,-Bstatic before -lSDL2 and -Wl,-Bdynamic after it. This statically links SDL2, but dynamically links all the other libraries.
The final command is:
gcc your_code.c -o your_executable -I/usr/local/include/SDL2 -D_REENTRANT \
-L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags \
-Wl,-Bstatic -lSDL2 -Wl,-Bdynamic -lm -ldl -lpthread -lrt
If your build of SDL2 is installed elsewhere, just change the /usr/local/include/SDL2 and /usr/local/lib part of the command to point to where the header files and .a files are respectively.
If I figure out how to cross-compile this setup, I will update this answer.

windows crosscompiling from linux entry point not found curl_easy_cleanup could not located

I am unsure of what could be causing this as I have tried recompiling libcurl and using pre-compiled binaries.
My compiler command
x86_64-w64-mingw32-gcc -Wall -Lwin-lib -Iwin-lib -I./ -D WIN32 -D CURL_STATICLIB -mwindows ... -o win-export/SLM.exe -lm -lraylib -ltmx -lxml2 -lzlibstatic -lcurl
There aren't any compiler errors or linker errors. Is this a problem with my compiler? Or one the other libraries I am using?

gcc cannot find -lglfw3 && i was unable to add the path

I am running CentOS 6.4, I have just installed GLFW 3.0.4 for some software package for CFD L-B visualisation. That's not my issue, the issue is that I was following instructions to test of GLFW was installed properly, I ran into some issues.
I began by
g++ -c main.cpp
Which has outputted main.o file, and went onto run this with the help of advice of another thread :
g++ main.o -o main.exec `pkg-config --libs glfw3` -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi -ldlD
which has then given me this error code:
Package glfw3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `glfw3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'glfw3' found
/usr/bin/ld: cannot find -lglfw3
collect2: ld returned 1 exit status
Have tried adding -L or -B to the path of glfw3.pc and no use,
Can you please advise on how I can get this to work properly?

Eclipse -lcurl not find

I need a special compiler. This is my call from eclipse:
powerpc-stw-linux-uclibc-g++ -L/usr/lib/i386-linux-gnu -L/usr/lib -L/usr/libx32 -L/var/lib -o "Test" ./src/Test.o -lz -lcurl
But now Eclipse throw this:
/opt/powerpc-gcc-4.4.3-uclib/bin/../lib/gcc/powerpc-stw-linux-uclibc/4.4.3/../../../../powerpc-stw-linux-uclibc/bin/ld: skipping incompatible /usr/lib/i386-linux-gnu/libcurl.so when searching for -lcurl
/opt/powerpc-gcc-4.4.3-uclib/bin/../lib/gcc/powerpc-stw-linux-uclibc/4.4.3/../../../../powerpc-stw-linux-uclibc/bin/ld: skipping incompatible /usr/lib/i386-linux-gnu/libcurl.a when searching for -lcurl
/opt/powerpc-gcc-4.4.3-uclib/bin/../lib/gcc/powerpc-stw-linux-uclibc/4.4.3/../../../../powerpc-stw-linux-uclibc/bin/ld: cannot find -lcurl
I tried to compile under Ubuntu 14.04 x86. libcurl should be installed
$ curl-config --libs
-L/usr/lib/i386-linux-gnu -lcurl
Obviously, you are building for PowerPC, but linking with the lib for i386.
You need to download/build libcurl for PowerPC, and provide the correct path to it.
In other words, don't mix two different architectures.

libpcap: 64bit machine has no compatible 32-bit libpcap library

I want to compile a .c file to 32-bit executable using gcc option -m32 with libpcap
the machine is linux 64bit fedora 16
however, I get the following error
[root#fdf source]# gcc -m32 -o test_tcp test_tcp.c -lpcap
/usr/bin/ld: skipping incompatible /usr/lib64/libpcap.so when searching for -lpcap
/usr/bin/ld: cannot find -lpcap
collect2: ld returned 1 exit status
I installed
yum install libpcap.i686
and then try to compile, but still get errors:
root#ddh-4.0# gcc -m32 -o test_tcp test_tcp.c -lpcap
/usr/bin/ld: skipping incompatible /usr/lib64/libpcap.so when searching for -lpcap
/usr/bin/ld: cannot find -lpcap
You need the development package in addition to the runtime library. So do
yum install libpcap-devel.i686

Resources