Wt Linking error on ubuntu - c++

I installed WT:
sudo apt-get install witty witty-dbg witty-dev witty-doc
and now, when linking the Hello World example,
g++ -std=c++14 -o hello HelloW.cpp -I./src -L/usr/lib/lib -lwthttp -lwt
I get this error:
undefined reference to `Wt::Signals::Impl::Connection::~Connection()'
I wonder what I'm doing wrong. (Please look the odd link path I had to use).
EDIT:
I looked for one of the lib I'm trying to link:
find /usr/ -name "*wthttp*"
/usr/share/lintian/overrides/libwthttp38
/usr/share/lintian/overrides/libwthttp-dev
/usr/share/doc/libwthttp38
/usr/share/doc/libwthttp-dev
/usr/lib/libwthttp.so
/usr/lib/debug/usr/lib/libwthttp.so.3.3.4
/usr/lib/libwthttp.so.3.3.4
/usr/lib/libwthttp.so.38
/usr/lib/libwthttp.a

Related

Installing Armadillo on macOS with homebrew

I am trying to install Armadillo with Homebrew with
brew install armadillo
but when I try to compile with
g++ example.cpp -o example -std=c++11 -O2 -larmadillo
it gives the following error:
fatal error: 'armadillo' file not found
How can I solve this problem?
I'm guessing here that you have a new M1 Mac. The issue in this case is that ARM-native homebrew is installed to /opt/homebrew/ by default, meaning armadillo was installed to /opt/homebrew/include/ which is not in your search path.
To see if this is the case, try providing the paths as follows:
CPATH=/opt/homebrew/include LIBRARY_PATH=/opt/homebrew/lib g++ example.cpp -o example -std=c++11 -O2 -larmadillo
To avoid the issue in general, I'm running with those CPATH and LIBRARY_PATH variables exported in my ~/.zprofile file (using zsh). I found this answer on the apple stack exchange helpful.

How do I install and use PNGwriter to write PNG image files?

I'd like to learn how to write PNG images pixel-by-pixel using both RGB and HSV color models with C++. I read that this should be fairly easy using PNGwriter (https://github.com/pngwriter/pngwriter), but I've spent many hours struggling with installing it (on Ubuntu) and compiling my code with it. Any help would be much appreciated.
Disclaimer: I have a weird background in the sense that I have many years of experience in using Unix-like operating systems, doing stuff in the terminal, and writing code, but I know little/nothing about installing software from the source code or compiling programs manually or with makefiles from multiple source code files.
The installation instructions on GitHub advise to do one of the following:
Spack:
spack install pngwriter
spack load pngwriter
From Source:
First install the dependencies zlib, libpng, and (optional for text support) freetype. PNGwriter >can then be installed using CMake:
git clone https://github.com/pngwriter/pngwriter.git
mkdir -p pngwriter-build
cd pngwriter-build
# for own install prefix append: -DCMAKE_INSTALL_PREFIX=$HOME/somepath
cmake ../pngwriter
make -j
# optional
make test
# sudo is only required for system paths
sudo make install
I managed to install Spack and then PNGwriter, but couldn't compile the simplest program with it and wasn't able to figure out why. I then installed PNGwriter manually, but still couldn't compile anything with it. This was many hours of struggling ago so I, unfortunately, don't remember what kind of errors or problems I was encountering at this point.
The instructions on GitHub say the following about linking:
First set the following environment hint if PNGwriter was not installed in a system path:
# optional: only needed if installed outside of system paths
export CMAKE_PREFIX_PATH=$HOME/somepath:$CMAKE_PREFIX_PATH
Use the following lines in your projects CMakeLists.txt:
find_package(PNGwriter 0.7.0)
if(PNGwriter_FOUND)
target_link_libraries(YourTarget PRIVATE PNGwriter::PNGwriter)
endif(PNGwriter_FOUND)
Questions: How do I know if PNGwriter was or wasn't installed in a system path? I have libPNGwriter.a in /usr/local/lib and pngwriter.h in /usr/local/include --- does this mean that it was installed in a system path? When installing I simply tried to follow the instructions above. Do I just type the environment hint to the terminal or add it to some file? If the former then does it need to be given every time I open a new terminal session? Is "somepath" /usr/local/lib, /usr/local/include or something else?
Questions: Does the second part regarding "CMakeLists.txt" depend on whether PNGwriter was installed in a system path? What is "CMakeLists.txt"? I assume it's some file one's IDE creates, but my NetBeans projects don't seem to contain such files. What if I have a single source file and compile it manually in the terminal?
Now, let's say I'd like to compile the PNGwriter quickstart example:
#include <pngwriter.h>
int main()
{
int i;
int y;
pngwriter png(300, 300, 0, "test.png");
for(i = 1; i ≤ 300; i++)
{
y = 150 + 100*sin((double)i*9/300.0);
png.plot(i, y, 0.0, 0.0, 1.0);
}
png.close();
return 0;
}
The PNGwriter manual instructs to compile as
g++ myprogram.cc -o my_program `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lpng -lpngwriter -lz -lfreetype
but I get errors
$ g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lpng -lpngwriter -lz -lfreetype
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'freetype2', required by 'virtual:world', not found
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'freetype2', required by 'virtual:world', not found
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'freetype2', required by 'virtual:world', not found
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
Package 'freetype2', required by 'virtual:world', not found
sed: -e expression #1, char 0: no previous regular expression
sed: -e expression #1, char 0: no previous regular expression
In file included from example.cpp:1:0:
/usr/local/include/pngwriter.h:66:22: fatal error: ft2build.h: No such file or directory
compilation terminated.
The answer to this Stack Overflow question (Trying to install pygame on ubuntu which gives error) suggests to install libfreetype6-dev, but I apparently have the latest version already whereby the errors remain unchanged. If I instead actually add the directory containing freetype2.pc (I found it by going to / and using find -name "freetype2.pc") to the environment variable (added export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH to ~/.bashrc and did source ~/.bashrc) then I get new errors
$ g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lpng -lpngwriter -lz -lfreetype
/usr/bin/ld: cannot find -lpngwriter
collect2: error: ld returned 1 exit status
Here I figured out that I needed to replace -lpngwriter with -lPNGwriter (i.e., the manual is erroneous). Then I get:
$ g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lpng -lPNGwriter -lz -lfreetype
/usr/bin/ld: /usr/local/lib/libPNGwriter.a(pngwriter.cc.o): undefined reference to symbol 'png_set_sig_bytes##PNG12_0'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
This is where I'm currently stuck. I can't seem to find a solution by googling (at least one that I'd understand).
Question: How do I get this working? How do I get it working in NetBeans? Do I get these problems because I effed up the linking step above?
Edit1: As per john's comment, I tried swapping -lpng and -lPNGwriter and I again get new errors:
$ g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lPNGwriter -lpng -lz -lfreetype
/usr/local/lib/libPNGwriter.a(pngwriter.cc.o): In function `pngwriter::close()':
pngwriter.cc:(.text+0x41c2): undefined reference to `png_convert_to_rfc1123_buffer'
/usr/local/lib/libPNGwriter.a(pngwriter.cc.o): In function `pngwriter::read_png_info(_IO_FILE*, png_struct_def**, png_info_def**)':
pngwriter.cc:(.text+0x4fdf): undefined reference to `png_set_longjmp_fn'
collect2: error: ld returned 1 exit status
I'm still left clueless.
Thanks to john, I think I got it figured out. My guess is that the installation from the source (after the Spack installation) messed things up somehow. I reinstalled PNGwriter using Spack and, now apparently having all the pieces for the compilation command, was finally able to compile the example code.
Summary:
Source Spack
# For bash/zsh/sh
$ . spack/share/spack/setup-env.sh
# For tcsh/csh
$ source spack/share/spack/setup-env.csh
# For fish
$ . spack/share/spack/setup-env.fish
Install using Spack (skip if already installed)
spack install pngwriter
Load PNGwriter (I guess one needs to do this in every new terminal session)
spack load pngwriter
Compile (note that this isn't quite what the PNGwriter manual suggests)
g++ example.cpp -o example `freetype-config --cflags` -I/usr/local/include -L/usr/local/lib -lPNGwriter -lpng -lz -lfreetype

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.

G++ cannot find library unless it is full path

After installing boost from EPEL 5 on 64-bit CentOS 5.8 I run insto strange problem. I cannot link in other way then providing full path. I.e this works:
g++ ... /usr/lib64/libboost_python.so.5
But this cannot find -lboost_python
g++ ... -L/usr/lib64/ -lboost_python
What could be wrong?
PS. LD_LIBRARY_PATH does not help. It do finds some libraries but even symlinking into /usr/lib does not help. I am building 64-version of program (checked by file *.o).
Try to add a symlink : ln -s /usr/lib64/liboost_python.so /usr/lib64/libboost_python.so.5, then try again.

libboost-system linker errors when cross-compiling to x86

I'm trying to build a 32-bit application on Ubuntu 11.04 x64. I'm having some issues with the build because of linker errors with libboost. The build statement has -lboost_system in it, but when I try to build I get a bunch of these:
CommunicationModule.cpp:(.text+0x68c1): undefined reference to boost::system::generic_category()
CommunicationModule.cpp:(.text+0x68d7): undefined reference to boost::system::system_category()
Everything I've found on google says I need to link to the boost_system library. One place I found says to try linking to it directly, but when i do locate boost_system the result is empty. When I try doing a sudo apt-get install libboost-system-dev it tells me that it's already installed. I'm kind of at a loss here. The library is installed, but it's not being found by locate?
Can anyone tell me what I need to do to properly link to boost::system? I'm fairly new to linux and the complexities of compilers so any help here would be appreciated.
Update:
Here is the output of dpkg -L libboost-system1.42-dev:
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libboost-system1.42-dev
/usr/share/doc/libboost-system1.42-dev/copyright
/usr/share/doc/libboost-system1.42-dev/NEWS.Debian.gz
/usr/share/doc/libboost-system1.42-dev/README.Debian.gz
/usr/lib
/usr/lib/libboost_system.a
/usr/lib/libboost_system-mt.so
/usr/lib/libboost_system-mt.a
/usr/lib/libboost_system.so
Is there a flag I can use to link to one of these directly? I tried using -L /usr/lib/libboost_system.so and -L /usr/lib/libboost_system-mt.so and neither of those fixed the issue. Same with just adding /usr/lib/libboost_system.a and /usr/lib/libboost_system-mt.a to the build statement.
Here is the compilation line:
g++ -m32 -Wl,-O1 -o UTNaoTool [.o files] -L/usr/lib32 -lqglviewer-qt4 -lqwt-qt4 -lboost_system -lboost_thread -lQtXml -lQtOpenGL -lQtGui -lQtNetwork -lQtCore -lGLU -lpthread
Update 2:
I downloaded boost 1.49 and built everything for 32-bit and that seemed to help. A lot of the errors went away, but now I still have these:
CommunicationModule.cpp:(.text+0x68c1): undefined reference to
boost::system::get_generic_category()
Note that the function is different. So all of my errors are regarding undefined references to get_system_category() and get_generic_category() now. I tried adding a -lboost_filesystem to the build command but that didn't fix this, and I made sure it was referencing the 32-bit library that I built when I built libboost_system.
Looking at my own installation, it seems libboost-system-dev does not install the libraries. Using dpkg to tell me what was installed bz libboost-system-dev I get:
$ dpkg -L libboost-system-dev
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libboost-system-dev
/usr/share/doc/libboost-system-dev/copyright
/usr/share/doc/libboost-system-dev/changelog.gz
Poking around, I think you need to install libboost-system1.48.1 (or some other version).
sudo apt-get install libboost-system1.XX.Y
You can also search fo rthe libraries using the find command, for example, search under /usr for all files starting with libboost_system:
find /usr -name "libboost_system*"
Edit: Since you are cross-compiling from a 64 bit OS to a 32 bit one, you need 32 bit versions of the boost libraries. I would be tempted to set up a small 32 bit virtual machine to do this, rather than cross-compiling all the dependencies.
I had the same problem with boost_serialization here is what i found out after couple of googling..
first this library need to be compiled separately :
so after downloading the boost library ,extract it and execute sudo ./bootstrap.sh' then
sudo ./b2 --with-system
after this step you should be find a result when executing locate boost_system
then to link it manually I did:
both should work
g++ boostexample.cpp -o run /PATH/libboost_serialization.a
g++ boostexample.cpp -o run -L/PATH/ -lboost_serialization
well this is a little work around and I'm still looking for how to link the library properly
I hope this helped :)