Static linking OpenSSL and cURL with Autotools and MinGW - c++

I'm trying to build a statically linked OpenSSL + LibCurl console application with CodeBlocks. However, I can't get it to work. I keep getting these errors:
||=== Build: Debug in Filer (compiler: GNU GCC Compiler) ===|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-openssl.o)|| undefined reference to `SSL_get0_alpn_selected'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-openssl.o)|| undefined reference to `SSL_CTX_set_alpn_protos'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-openssl.o)|| undefined reference to `SSL_CTX_set_next_proto_select_cb'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-openssl.o)|| undefined reference to `SSL_CTX_set_srp_username'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-openssl.o)|| undefined reference to `SSL_CTX_set_srp_password'|
C:\MinGW\msys\1.0\local\lib\libcurl.a(libcurl_la-openssl.o)|| undefined reference to `SSL_COMP_free_compression_methods'|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
This is the build log:
mingw32-g++.exe -o bin\Debug\Filer.exe "obj\Debug\MinGW Sources\BASE64\base64.o
" "obj\Debug\MinGW Sources\SQLite\sqlite3.o" obj\Debug\Users\thoma\Desktop\Filer
\main.o -static -lcurl -lrtmp -lidn -lssl -lssh2 -lcrypto -lz -lwldap32 -lws2_
32 -lwinmm -lgdi32 C:\MinGW\msys\1.0\local\lib\libcrypto.dll.a C:\MinGW\msys\1.0
\local\lib\libcurl.a C:\MinGW\msys\1.0\local\lib\libcurl.dll.a C:\MinGW\msys\1.0
\local\lib\libssl.a C:\MinGW\msys\1.0\local\lib\libssl.dll.a C:\MinGW\msys\1.0\l
ocal\lib\libwxjpeg-3.0.a C:\MinGW\msys\1.0\local\lib\libwxpng-3.0.a C:\MinGW\msy
s\1.0\local\lib\libwxscintilla-3.0.a C:\MinGW\msys\1.0\local\lib\libwxtiff-3.0.a
C:\MinGW\msys\1.0\local\lib\libz.a C:\MinGW\msys\1.0\local\lib\libz.dll.a
I have used the set-up which is outlined here.
Some pictures of my setup:

You have a mismatch between your OpenSSL version and the OpenSSL version used by libcurl.

Related

Codeblocks doesn't support glfw3?

I'm learning opengl and wanted to use Codeblocks IDE because visual studio seems too laggy and slow. After starting a console application project i've tried to link GLFW3 library to make this code run:
#include <GLFW/glfw3.h>
#include <thread>
int main()
{
glfwInit();
std::this_thread::sleep_for(std::chrono::seconds(1));
glfwTerminate();
}
I use GNU GCC 32-bit Compiler from MinGW(one that comes with codeblocks installation). I'm pretty certain that i've done everything correctly, i've read through like every article that i was able to find explaining how to setup codeblocks for opengl. I've linked libglfw3.a and libglfw3dll.a and set up correct search directories for compiler and linker but i always get this undefined reference error no matter what:
-------------- Build: Debug in glfw_again_test (compiler: GNU GCC Compiler)---------------
g++.exe -L"C:\Program Files\CodeBlocks\MinGW\lib" -o bin\Debug\glfw_again_test.exe obj\Debug\main.o "C:\Program Files\CodeBlocks\MinGW\lib\libglfw3.a" "C:\Program Files\CodeBlocks\MinGW\lib\libglfw3dll.a" "C:\Program Files\CodeBlocks\MinGW\x86_64-w64-mingw32\lib\libopengl32.a"
obj\Debug\main.o: In function `main':
C:/dev/OpenGL/CodeBlocks/glfw_again_test/main.cpp:6: undefined reference to `glfwInit'
C:/dev/OpenGL/CodeBlocks/glfw_again_test/main.cpp:8: undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
3 error(s), 0 warning(s) (0 minute(s), 1 second(s))
I have no idea what else i could try to fix this problem.
Apparently i was mistaken and thought that i use 32-bit MinGW compiler but seems like i accidentally installed 64-bit one with codeblocks. After switching to mingw gcc 32-bit compiler and rebuilding(simple build will lead to an error) my project i finally got it to work(not exactly this code snippet but another sample one).

"Undefined reference" errors when including <iostream>

I have started a new console application (C++) in Code::Blocks 17.12 with Cygwin compiler and g++ 7.3.0, and I have only "main.cpp" which have a very small code:
#include<iostream>
using namespace std;
int main(){
cout<<"test";
return 0;
}
I clicked build and got 16 errors, Here's the build log:
-------------- Build: Debug in 1 (compiler: Cygwin g++)---------------
g++.exe -Wall -fexceptions -g -std=c++14 -IC:\cygwin\usr\include -c C:\Users\Windows7\Desktop\BASIL\1\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\cygwin\lib -o bin\Debug\1.exe obj\Debug\main.o
obj\Debug\main.o: In function `_static_initialization_and_destruction_0':
/usr/lib/gcc/i686-pc-cygwin/7.3.0/include/c++/iostream:74: undefined reference to `__dso_handle'
/usr/lib/gcc/i686-pc-cygwin/7.3.0/include/c++/iostream:74: undefined reference to `__cxa_atexit'
C:\cygwin\lib/libpthread.a(t-d001702.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_destroy'
C:\cygwin\lib/libpthread.a(t-d001704.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_init'
C:\cygwin\lib/libpthread.a(t-d001709.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_unlock'
C:\cygwin\lib/libpthread.a(t-d001720.o):fake:(.text+0x2): undefined reference to `_imp__pthread_once'
C:\cygwin\lib/libpthread.a(t-d001705.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_lock'
C:\cygwin\lib/libpthread.a(t-d001699.o):fake:(.text+0x2): undefined reference to `_imp__pthread_key_create'
C:\cygwin\lib/libpthread.a(t-d001697.o):fake:(.text+0x2): undefined reference to `_imp__pthread_getspecific'
C:\cygwin\lib/libpthread.a(t-d001741.o):fake:(.text+0x2): undefined reference to `_imp__pthread_setspecific'
C:\cygwin\lib/libpthread.a(t-d001679.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_wait'
C:\cygwin\lib/libpthread.a(t-d001674.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_broadcast'
C:\cygwin\lib/libpthread.a(t-d001700.o):fake:(.text+0x2): undefined reference to `_imp__pthread_key_delete'
C:\cygwin\lib/libpthread.a(t-d001675.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_destroy'
C:\cygwin\lib/libpthread.a(t-d001677.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_signal'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
16 error(s), 0 warning(s) (0 minute(s), 3 second(s))
I also edited the compiler, the linker and the resource compiler in search directories tab according to the documentation but that didn't work.
please help me in this!
Thanks,
Finally fixed it! Just giving the answer to people still searching,
just install Cygwin and go to settings -> compiler in code::blocks and pick Cygwin GCC instead of GNU GCC compiler, go to the Toolchain excutables and change the "Compiler's Installation Directory" to your Cygwin directory and change the "Program files" to your cygwin programs (if they're not already modified), the compiler window should look like the screenshot attached.

Undefined reference to SDL_init, build log unclear

I have just setup SDL on CodeBlocks, and I am getting a build error:
-------------- Build: Debug in SDL learning (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -L..\deps\lib -o "bin\Debug\SDL learning.exe" obj\Debug\main.o -lmingw32 -lSDL2main -lSDL2
obj\Debug\main.o: In function `SDL_main':
C:/Users/73638G75MA/Documents/prive/programeren/C++ projects/SDL learning/main.cpp:7: undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
The build log doesn't really tell me anything, maybe some of you guys know a solution.
In case you need my code:
#include <iostream>
#include <SDL.h>
using namespace std;
int main(int argc, char *argv[]){
if(SDL_Init(SDL_INIT_EVERYTHING)!=0){
cout << "Could not initiate SDL" << endl;
}
return 0;
}
I got my include and lib files in folder named deps.
Also, it does recognize the SDL.h file and its commands, because when I type #include <S it suggests SDL.h. It also autocompletes the SDL commands.

c++ files to include for boost : asio

I'm following this tutorial however it does not state which libaries I need to include in order to get boost to work,current options for links are:
-I/usr/include/opencv2 -I/usr/include/boost_1_55_0 -I/usr/include/boost_1_55_0/boost -O0 -g3 -Wall -c -fmessage-length=0
however this returns the following erro:
which states that it can't find asio, am I doing something wrong or was assio the wrong library to link to? Or is there any other way to find out. Note that this is my 2nd c++ project(through I have a lot of java experience) and first with the heavy use of libraries so details are somewhat required.
Removing boost/asio gave me the following errors:
make all
Building target: DisplayImage
Invoking: GCC C++ Linker
g++ -L/usr/include/opencv2 -L/usr/include/boost_1_55_0/boost -L/usr/include/boost_1_55_0 -L/usr/include/opencv2 -L/usr/lib -o "DisplayImage" ./src/Cap.o ./src/DisplayImage.o ./src/Filters.o ./src/sender.o -lopencv_imgproc -lopencv_highgui -lopencv_core
./src/sender.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost_1_55_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/include/boost_1_55_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/include/boost_1_55_0/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
./src/sender.o: In function `error_code':
/usr/include/boost_1_55_0/boost/system/error_code.hpp:323: undefined reference to `boost::system::system_category()'
./src/sender.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost_1_55_0/boost/asio/error.hpp:224: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [DisplayImage] Error 1
Build Finished **
I use an ubuntu (x64) laptop if it matters.
Most of boost is implemented in what's called "header-only" code. Through the generous use of C++ templates, there is no actual library code to which your code needs to link. However, there are, as you've seen some actual libraries as well. Generally, the help you seek is probably here: http://www.boost.org/doc/libs/1_55_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library
Your particular program uses the timer and system libraries and so you can probably use this command line to link your program:
g++ timer.cpp -o timer -lboost_timer -lboost_system
You can look at the bjam in boost/libs/asio/example/cpp03/tutorial/Jamfile.v2:
project
: requirements
<library>/boost/system//boost_system
<library>/boost/thread//boost_thread
<define>BOOST_ALL_NO_LIB=1
<threading>multi
<os>SOLARIS:<library>socket
<os>SOLARIS:<library>nsl
<os>NT:<define>_WIN32_WINNT=0x0501
<os>NT,<toolset>gcc:<library>ws2_32
<os>NT,<toolset>gcc:<library>mswsock
<os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
<os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
<os>HPUX:<library>ipv6
;
You can see that they build all the tutorial steps with
-lboost_system -lboost_thread -DBOOST_ALL_NO_LIB=1
on linux

Compile C++ and OpenSSL on Ubuntu 11.10

I got a serious problem compiling my C++ and OpenSSL project on my Ubuntu 11.10.
The compiling command is:
g++ -Wall -lssl -lm -lcrypto -I ./src ./src/server.cpp -o ./bin/server
I receive these errors:
server.cpp:(.text+0x8ff): undefined reference to `RSA_new'
server.cpp:(.text+0x92d): undefined reference to `PEM_read_RSAPrivateKey'
server.cpp:(.text+0xa85): undefined reference to `RSA_size'
server.cpp:(.text+0xaa1): undefined reference to `RSA_size'
server.cpp:(.text+0xae7): undefined reference to `RSA_private_decrypt'
server.cpp:(.text+0xd84): undefined reference to `BF_set_key'
server.cpp:(.text+0xf1d): undefined reference to `BF_ecb_encrypt'
server.cpp:(.text+0x13c6): undefined reference to `BF_ecb_encrypt'
collect2: ld returned 1 exit status
make: *** [server] Error 1
I successfully installed openssl and libssl-dev but the problem persists.
I tried to compile the project on Linux Mint 12 with the kernel 3.0 and I had the same problem.
On my old Linux OS with the kernel 2.6 the project compiled and worked fine (using the same Makefile and the same sources).
Please help me!
Generally you need to have the -l link flags after the code that references them. Try
g++ -Wall -I ./src ./src/server.cpp -o ./bin/server -lssl -lm -lcrypto
As the comment to this answer states, the linker only looks for undefined symbols to include in the order the parameters are listed.
That is, if your cpp file uses the libraries, the libraries have to be listed after the cpp file.
Those error are from crypto library, check whether ssl and crypto libraries are available in /usr/lib or where ever u installed if not install them and have u set the library search path for libssl and libcrypto in your compiling command?