Compiling boost_asio/example/ssl/server.cpp on macosx works on linux - c++

server.cpp - http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/server.cpp
I am trying to build this on my mac. Using the following. (builds fine on my ubuntu system)
g++ -I /usr/local/boost/ sslserver.cpp -o sslserver -lboost_system -lssl -lpthread
My libs are located in /usr/local/lib so I tried adding -L /usr/local/lib after the includes. However, I have built other projects before using -lboost_system -lpthread without any issues or specifying the libs.
The error is huge > https://dl.dropbox.com/u/15586644/error.txt
Its mainly lots of deprecated methods warnings - I doubt anything is deprecated.
followed by Undefined symbols for architecture x86_64.
How should I go about building server.cpp on MacOSX?

See
- Why is Apple Deprecating OpenSSL in MacOS 10.7 (Lion)?
Apple is migrating from OpenSSL to Common Crypto, hence depreciated warnings

Related

Building GDAL with all libraries static

I want to develop a small program that checks which polygons from a shapefile intersect a given rectangle. This program is to be used in a website (with PHP's exec() command). The problem is, my webserver cannot install GDAL, for reasons unknown to me. So I can't link to the shared libraries. Instead, I must link to static libraries, but these aren't given.
I've downloaded the GDAL source code from here (2.3.2 Latest Stable Release - September 2018), and followed the build instructions from here. Since I already have GDAL working on my Debian, and don't want to mess with it, I followed the "Install in non-root directory" instructions, with some adjusts from the last item in the "Some caveats" section:
cd /home/rodrigo/Downloads/gdal232/gdal-2.3.2
mkdir build
./configure --prefix=/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/ --without-ld-shared --disable-shared --enable-static
make
make install
export PATH=/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/bin:$PATH
export LD_LIBRARY_PATH=/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib:$LD_LIBRARY_PATH
export GDAL_DATA=/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/share/gdal
/usr/bin/gdalinfo --version
build/bin/gdalinfo --version
The first /usr/bin/gdalinfo --version gives 2.1.2 (the previous installed version). The second, build/bin/gdalinfo --version, gives 2.3.2 (the version just built).
By now, my program only uses the ogrsf_frmts.h header, which is in /usr/include/gdal/ or /home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/include/ directory, depending on the build. There's no ogrsf_frmts.a file, but only a libgdal.a. Is this the file I should be linking against? If so, how? I've tried so far:
gcc geofragc.cpp -l:libgdal.a
gcc geofragc.cpp -Wl,-Bstatic -l:libgdal.a
gcc geofragc.cpp -Wl,-Bstatic -l:/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
gcc geofragc.cpp -Wl,-Bstatic -l/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
gcc geofragc.cpp /home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
gcc geofragc.cpp -l/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
gcc geofragc.cpp -l:/home/rodrigo/Downloads/gdal232/gdal-2.3.2/build/lib/libgdal.a
but nothing works. What am I missing?
EDIT
The second trial (gcc geofragc.cpp -Wl,-Bstatic -l:libgdal.a) is giving the following error:
/usr/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-linux-gnu/6/../../../../lib/libgdal.a(gdalclientserver.o): In function `GDALServerSpawnAsync()':
(.text+0x1f5e): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
You can use the gdal-config program to get correct options for compilation and linking. This program is a part of the GDAL library and it has its own options:
hekto#ubuntu:~$ gdal-config --help
Usage: gdal-config [OPTIONS]
Options:
[--prefix[=DIR]]
[--libs]
[--dep-libs]
[--cflags]
[--datadir]
[--version]
[--ogr-enabled]
[--gnm-enabled]
[--formats]
You have to make sure this program is on your search path, or you can create an alias - for example:
alias gdal-config='/home/rodrigo/Downloads/gdal232/gdal-2.3.2/bin/gdal-config'
Now your compilation and linking command becomes the following one:
g++ `gdal-config --cflags` geofragc.cpp `gdal-config --libs` `gdal-config --dep-libs`
You have to use the g++ compiler to link with C++-built libraries.
Another option is to create a Makefile with these lines:
CXXFLAGS += ${shell gdal-config --cflags}
LDLIBS += ${shell gdal-config --libs}
LDLIBS += ${shell gdal-config --dep-libs}
geofragc: geofragc.cpp
and just call make with this Makefile.
I hope, it'll help.

Qt5.5 static build cannot find -IGL on ubuntu14

I have compiled qt 5.5 for static building and it works fine.
However, when I add the widgets "QT += widgets" in the pro file I get the link error "cannot find -IGL"
From what I read this is to do with the Open GL libs. I have tried the following:
sudo apt-get install libglu1-mesa-dev
and
sudo apt-get install libgl1-mesa-dev
But no luck here... I am wondering if I need a static version of this? or maybe a symlink is missing, but I can't figure out the next step :(
Edit This is the actual error message:
g++ -static -static-libgcc -static-libstdc++ -Wl,-O1 -o ../targetRel/McpSupervisor main.o cconfig.o cconfigxml.o mcpprocessbase.o rpeprocess.o supervisor.o cipcomms.o mcpsupervisor_plugin_import.o moc_mcpprocessbase.o moc_supervisor.o moc_cipcomms.o -L/usr/lib/i386-linux-gnu/mesa -L/usr/local/Qt-5.5.1/lib -lQt5Xml -lQt5Widgets -L/usr/local/Qt-5.5.1/plugins/bearer -lqconnmanbearer -lqgenericbearer -lqnmbearer -lQt5Network -L/usr/local/Qt-5.5.1/plugins/platforms -lqxcb -L/usr/local/Qt-5.5.1/plugins/xcbglintegrations -lqxcb-glx-integration -lxcb-glx -lQt5XcbQpa -lX11-xcb -lXi -lxcb-render-util -lxcb-render -lxcb -lxcb-image -lxcb-icccm -lxcb-sync -lxcb-xfixes -lxcb-shm -lxcb-randr -lxcb-shape -lxcb-keysyms -lxcb-xkb -lQt5PlatformSupport -lfontconfig -lfreetype -lQt5DBus -lXrender -lXext -lX11 -L/usr/local/Qt-5.5.1/plugins/imageformats -lqdds -lqicns -lqico -lqjp2 -lqmng -lqtga -lqtiff -lqwbmp -lqwebp -lQt5Gui -lpng -lqtharfbuzzng -lQt5Core -lz -licui18n -licuuc -licudata -lqtpcre -lm -ldl -pthread -lgthread-2.0 -lglib-2.0 -lrt -lGL -lpthread
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libX11.a(CrGlCur.o): In function open_library':
(.text+0x33): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lGL
/usr/local/Qt-5.5.1/plugins/imageformats/libqjp2.a(jas_stream.o): In functionjas_stream_tmpfile':
jas_stream.c:(.text+0x7a4): warning: the use of tmpnam' is dangerous, better usemkstemp'
/usr/local/Qt-5.5.1/lib/libQt5Core.a(qfilesystemengine_unix.o): In function QFileSystemEngine::resolveGroupName(unsigned int)':
qfilesystemengine_unix.cpp:(.text+0x943): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libglib-2.0.a(libglib_2_0_la-gutils.o): In functiong_get_user_database_entry':
(.text+0x25a): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libglib-2.0.a(libglib_2_0_la-gutils.o): In function g_get_user_database_entry':
(.text+0xa3): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/Qt-5.5.1/lib/libQt5Core.a(qfilesystemengine_unix.o): In functionQFileSystemEngine::resolveUserName(unsigned int)':
qfilesystemengine_unix.cpp:(.text+0x592): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/Qt-5.5.1/lib/libQt5Network.a(qhostinfo_unix.o): In function `QHostInfoAgent::fromName(QString const&)':
qhostinfo_unix.cpp:(.text+0x580): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
make: *** [../targetRel/McpSupervisor] Error 1
09:49:17: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project qtMain (kit: Qt 5.5.1 GCC 32bit Static)
When executing step "Make"
09:49:17: Elapsed time: 00:08.
What is your actual problem :
You have unmet dependencies .
You are thinking that you have all the required dependencies because you installed
sudo apt-get install libglu1-mesa-dev
sudo apt-get install libgl1-mesa-dev
The problem is that you have a i386 system that is x32 system.
But you have installed development files for x64 systems using the commands above
Here is the ANSWER :
Intsall the following things
sudo apt-get install libgl1-mesa-dev:i386
sudo apt-get install libglu1-mesa-dev:i386
Now it should work ;)
Some other helpful stuff for visitors to this particular question
The lines below were my attempt to solve the problem but they did not work because the person who asked the question has a x32 system but the comments below work for x64 systems . But never the less the meta answer below will serve well for people who have the same problem and x64 systems. And also it will help problem to understand what are the basic steps to do after a similar problem occurs
# code_fodder I wanted to ask a question by making a comment below your question but I do not have 50 reputations to do so.
So I have to use the answer submission form to do so. :(
Do you have Miscellaneous Mesa GL utilities ?
If you dont have them then install using
sudo apt-get install mesa-utils
If you want to use OpenGl ES then you have to install Miscellaneous Mesa utilies (opengles, egl) using
sudo apt-get install mesa-utils-extra
Let me know if that works .
POSTING NEW INFORMATION ON 17-DEC-2015
I will post a portion of my project.pro file here . It specifically contains the library linking methods that I used for a simple OpenGL project.
I am using GLEW with OpenGL and SDL2
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
mesh.cpp \
display.cpp \
shader.cpp
HEADERS += \
mesh.h \
display.h\
shader.h
unix|win32: LIBS += -lGL \
-lGLEW \
/usr/local/lib/libSDL2-2.0.so
As you can notice I am using both static and dynamically linked libraries.
You may need to add:
unix | win32: LIBS += -L/usr/lib/x86_64-linux-gnu/mesa/ to your .pro file. However the path may be different for 32 bit systems. In that folder there are is the required mesa library files. These are the files for my system.
zehel#zehel-PC:/usr/lib/x86_64-linux-gnu/mesa$ ls
ld.so.conf libGL.so libGL.so.1 libGL.so.1.2.0
Try compiling now and see if that works
If that doesn't then either you have unmet dependencies or you are using old OpenGL.
Now after running the sudo apt-get install mesa-utils you will be able to use a command called glxinfo . It will show you all required information about your graphics card.
Run glxinfo | grep "OpenGl version string"
It will show you what version of OpenGl and mesa you have
mine is like this
OpenGL version string: 3.0 Mesa 10.3.2
If they are less than 3.0 then you are not using modern OpenGL and you may want to update your graphics drivers.
But if they are 3.0 or above then you are probably okay.
I cant reproduce your problem so I think that you have missing dependencies
See this posts on the QT forum where people with same problem as you are saying that there problems were fixed after installing the dependencies
http://forum.qt.io/topic/36282/solved-qt-5-2-0-and-lgl-issue
The last answer in the qt forum is quite good please refer it.
Update me whether it works or not .
Hope That helps .
You might need to specify the path where the GL library can be found, for exmaple by using the -L option to GCC, which has the following man page description:
-Ldir
Add directory dir to the list of directories to be searched for -l.

Did upgrading to Ubuntu 14.04 break the c++ linker?

I have a Linux-based application, running under Ubuntu 12.04 LTS, that compiled, linked, and ran with no problem.
I recently upgraded my Ubuntu to 14.04 LTS and encountered problems compiling and linking the app.
The compilation problems were solved by manually modifying my local copy of Boost 1.48 in two files (include/boost/config/stdlib/libstdcpp3.hpp and include/boost/thread/xtime.hpp). At this point the app compiled successfully.
The problem I have is that the linkage fails with the error message:
c++: error: unrecognized command line option ‘-Wl’
I use CMake to enable compiling the app on multiple platforms. Here is the linker script generated by CMake. Note that the "-Wl" options are now inexplicably unrecognized by /usr/bin/c++:
/usr/bin/c++
-fno-stack-protector
-g
-Wl
CMakeFiles/Project.dir/main.cpp.o
CMakeFiles/Project.dir/TestCallback.cpp.o
CMakeFiles/Project.dir/utils.cpp.o
CMakeFiles/Project.dir/Request1.cpp.o
CMakeFiles/Project.dir/Response1.cpp.o
CMakeFiles/Project.dir/TextChatRequest.cpp.o
CMakeFiles/Project.dir/TextChatResponse.cpp.o
-o
/home/user/private/Project/Project_Release_1_2_Codename/Build/bin/Debug/Project
-L/home/user/Libraries/Ubuntu32_12.04/boost_1.48/lib
-L/home/user/Libraries/Ubuntu32_12.04/SqlLite_3.6/lib
-L/home/user/Libraries/Ubuntu32_12.04/taglib_1.7/lib
-L/home/user/Libraries/Ubuntu32_12.04/JSON_1.0/lib/Debug
-L/home/user/private/Project/Project_Release_1_2_Codename/Build/../lib/libUbuntu32/Debug
-rdynamic
/home/user/private/Project/Project_Release_1_2_Codename/lib/libUbuntu32/Debug/libAPI.a
/home/user/private/Project/Project_Release_1_2_Codename/lib/libUbuntu32/Debug/libInternals.a
-lboost_thread
-lboost_system
-lboost_filesystem
-lboost_program_options
-ltaglib
-lJSON
-lpthread
-Wl,-Bstatic
-lsqlite3
-Wl,-Bdynamic
-ldl
-Wl,-rpath,/home/user/Libraries/Ubuntu32_12.04/boost_1.48/lib:/home/user/Libraries/Ubuntu32_12.04/SqlLite_3.6/lib:/home/user/Libraries/Ubuntu32_12.04/taglib_1.7/lib:/home/user/Libraries/Ubuntu32_12.04/JSON_1.0/lib/Debug:/home/user/private/Project/Project_Release_1_2_Codename/Build/../lib/libUbuntu32/Debug
Here is version information for the software I'm using:
Ubuntu:
14.04.1 LTS (trusty)
c++ compiler/linker:
(Ubuntu 4.8.2-19ubuntu1) 4.8.2
CMake:
Version 2.8.12.2
Why doesn't the linker recognize "-Wl" commands? Did my upgrade to 14.04 LTS modify the linker software libraries? How can I get my app back up and linking?
On line 4 of the command you have -Wl without any actual linker options.
https://gcc.gnu.org/gcc-4.7/porting_to.html
Right at the top of this page is the following:
Earlier releases did not warn or error about completely invalid
options on gcc/g++/gfortran etc. command lines, if nothing was
compiled, but only linking was performed. This is no longer the case.
For example,
gcc -Wl -o foo foo.o -mflat_namespace
Now produces the following error
error: unrecognized command line option ‘-Wl’
error: unrecognized command line option ‘-mflat_namespace’
Invalid options need to be removed from the command line or replaced by something that is valid.
12.04 LTS packaged GCC 4.6, you've now jumped to 4.8 and -Wl on its own is no longer a valid option (or rather it never was, GCC is just more pedantic now).
As mentioned by others previously, it indeed turned out that my CMake script was injecting a lone, solitary, seemingly unnecessary "-Wl" via the CMAKE_EXE_LINKER_FLAGS setting:
if(LINUX)
set(THIRDPARTY_LIBS boost_thread boost_system boost_filesystem boost_program_options taglib JSON)
set(OS_LIBS pthread sqlite3.a dl)
set(CMAKE_EXE_LINKER_FLAGS "-Wl")
set(PREPROCESSOR_DEFINITIONS ${PREPROCESSOR_DEFINITIONS};/DTAGLIB_STATIC)
endif(LINUX)
When I removed this setting, the build succeeded. This oversight has been around a while, with the earlier version of gcc not minding. The latest gcc, however, is more pedantic and flagged it as an error.

Compiling Boost example projects with Cygwin + gcc

While trying to compile the boost asio example project
async_tcp_echo_server.cpp
I get errors like the following:
__MSABI_LONG was not declared in this file scope
BOOST_ASIO_NATIVE_ERROR(ERROR_BROKEN_PIPE)
__MSABI_LONG was not declared in this file scope
BOOST_ASIO_NATIVE_ERROR(ERROR_OPERATION ABORTED)
This is with Boost 1.55.0 and gcc version 4.8.3
boost was compiled with gcc and the following commands
./bootstrap.sh
./b2 cxxflags="-D__USE_W32_SOCKETS -D_WIN32_WINNT=0x0501
./b2 install
I attempted to compile the sample project with
gcc -std=C++11 -D__USE_W32_SOCKETS -D_WIN32_WINNT=0x0501 -I C:\boost_1_55_0 C:\boost_1_55_0\boost\asio.hpp async_tcp_echo_server.cpp
I know this is kind of old thread.
I managed to fix it by reinstalling the boost lib via Cygwin setup_x86.exe.
The version I installed is 1.57. And you don't have to put -D option in the command line.
Hope this may help.
1_57 version from cygwin setup doesn't help for me, it gives me fd_set errors.
This is what I tried to make the boost example code work:
add #define __MSABI_LONG(x) x at the top. - chilly, I know :)
add these flags to g++:-D_WIN32_WINNT=0x0501 -D__USE_W32_SOCKETS -std=c++11 -lboost_system -lws2_32
Voila!

Mongodb c++ driver - linking error: using deprecated boost::stystem::get_generic_category()

I have successfully installed and run mongodb on my macbook pro with
the c++ driver, but when I am trying to do the same on a computer in
school (need to do lengthy simulations) I encounter some errors. The
database itself works nicely, but when I try to compile my program I
get a lot of these errors:
/chalmers/users/X/thesis/libs/mongo-cxx-driver-nightly//
libmongoclient.a(spin_lock.o): In function
`__static_initialization_and_destruction_0(int, int)':
spin_lock.cpp:(.text+0x44): undefined reference to
`boost::system::get_system_category()' spin_lock.cpp:(.text+0x50):
undefined reference to `boost::system::get_generic_category()'...
I have downloaded, built and tried boost versions 1.4.8, 1.4.7 and
1.44.0. As I understand get_system_category() and
get_generic_category() are both deprecated and replaced by the same
method name with the "get" dropped. However, on my macbook I use boost
1.4.7 and it works..
I have tried both nightly and latest 2.0 version of the c++ driver. I
still get the same error. The computer in school is a RedHat
Enterprice Linux Server. It doesn't have libboost_system in the /usr/lib folder. Since I don't have root access I have
downloaded and built the libraries needed (boost, libcurl) and I am
pointing to those in by makefile:
path = ./build/
Ipath = -I/../mongo-cxx-driver-v2.0/mongo/ - I/.../boost_1_44_0/
Lpath = -L/.../mongo-cxx-driver-nightly/ -L/.../boost_1_44_0/stage/lib -L/.../curl/lib
libs = -lboost_system -lmongoclient -lboost_thread -lboost_filesystem -lboost_program_options -lcurl
db: sdc.o main.cpp
g++ main.cpp $(path)sdc.o $(Ipath) $(Lpath) $(libs) -o $ (path)db
sdc.o: ../controller.h ../controller.cpp
g++ -c ../controller.cpp -o ./build/sdc.o $(Ipath)
Has anyone else had this problem? Does anyone see what I am doing
wrong here?
Thanks
It worked with boost version 1.42..