Compiling gcc-4.8.1: "libmpc.so.2 cannot open shared object file download prerequisites" - c++

Many people appear to have encountered this problem. The GNU website strongly recommends running
./contrib/download_prerequisites
in the source directory to avoid problems with linking MPC, MPFR and GMP. The following link contains the instructions I've followed: http://gcc.gnu.org/wiki/InstallingGCC which I've listed here:
tar xzf gcc-4.8.1.tar.gz
cd gcc-4.8.1
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.8.1/configure --prefix=$HOME/gcc-4.8.1-install
make
make install
The FAQ at this url: http://gcc.gnu.org/wiki/FAQ#configure_suffix claims that the compilation will have no problem finding MPC related files so long as they are located in a subdirectory of the gcc-4.8.1 source directory. Running
./contrib/downlaod_prerequisites
downloads MPC in the correct location, yet I still get this error after running make:
checking for x86_64-unknown-linux-gnu-gcc... /home/xxxx/gcc-4.8.1-build/./gcc/xgcc -B/home/xxxx/gcc-4.8.1-build/./gcc/ -B/home/xxxx/gcc-4.8.1-install/x86_64-unknown-linux-gnu/bin/ -B/home/xxxx/gcc-4.8.1-install/x86_64-unknown-linux-gnu/lib/ -isystem /home/xxxx/gcc-4.8.1-install/x86_64-unknown-linux-gnu/include -isystem /home/xxxx/gcc-4.8.1-install/x86_64-unknown-linux-gnu/sys-include
checking for suffix of object files... configure: error: in `/home/xxxx/gcc-4.8.1-build/x86_64-unknown-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
Opening /home/xxxx/gcc-4.8.1-build/x86_64-unknown-linux-gnu/libgcc/config.log reveals the following error:
/home/mgiamou/gcc-4.8.1-build/./gcc/cc1: error while loading shared libraries: libmpc.so.2: cannot open shared object file: No such file or directory
The GNU FAQs (http://gcc.gnu.org/wiki/FAQ#configure_suffix) say that this error is symptomatic of not having properly installed MPC. Any help would be much appreciated.

I didn't have the latest version of binutils installed. Be sure to have the latest version whenever installing the latest gcc.

Related

fatal error: 'openssl/evp.h' file not found cmake + make

Operating system: macOS Catalina
I have a project that has a file called CMakeLists.txt. I ran cmake and then make, but the make command failed:
/Users/blablabla/Downloads/myproject/src/main.cpp:10:10: fatal error:
'openssl/evp.h' file not found
#include <openssl/evp.h>
I tried reinstalling OpenSSL via homebrew, linking the libraries but it still gave this error.
What am I could be doing wrong?
Any help would be highly appreciated
either openssl's dev library is not installed, or the g++ command that cmake generates probably is missing a -I.
try sudo apt-get install libssl-dev first and if that doesn't work, make sure the openssl include dir is provided to g++.
according to https://cmake.org/cmake/help/v3.6/module/FindOpenSSL.html, it creates an env var of OPENSSL_INCLUDE_DIR
edit: just noticed you're on OSX. you can install the the dev libssl package with brew install openssl

How to install Boost from source

I am trying to install the Boost C++ from source.
I first tried using yum to install them in (Amazon Linux AMI) but it installed a version that is too old. I need at least version 1.54
So I tried to follow the instructions here:
https://www.boost.org/doc/libs/1_70_0/more/getting_started/unix-variants.html
Once I downloaded the source, I tried symlinking the header files to /usr/include:
ln -s /root/boost_1_70_0/boost /usr/include/boost
Then I followed the instructions to try to build:
cd /root/boost_1_70_0
./bootstrap.sh
./b2 install
Then when I try to compile my program that needs boost libraries (happens to be OSRM), I get this error:
make[2]: *** No rule to make target `/usr/lib64/libboost_date_time-mt.so', needed by `osrm-components'. Stop.
So it seems somehow I need to build the boost .so files to go in /usr/lib64. But how do I do that?
I believe that you've already built the boost .so files but I don't know where. It normally tries to install them in /usr/local, see section 5.1 of the instructions you referenced.
You may be able to find them with locate, e.g.:
locate boost
Otherwise, you can call ./bootstrap.sh with a prefix indicating where you want it to build the libraries, e.g.:
./bootstrap.sh --prefix=/root/boost_1_70_0/stage
./b2 install
You can then copy the .so files together with with their symbolic links to /usr/lib64, e.g.:
cd /usr/lib64
rm -fr libboost*
cp -a /root/boost_1_70_0/stage/lib/libboost* .
chmod a+x libboost*
Note: the line rm -fr libboost* in /usr/lib64 is to remove the very old version of boost that you installed with yum.

CMake/Make cannot find libusb

I'm new to C/C++ and am trying to build and run ttwatch from github locally on an Ubuntu machine (Trusty Tahr). Instructions include installing some libraries first: cmake, openssl, curl, libusb, and include a note to install the "-dev" versions (eg. libssl-dev, libcurl-dev, libusb-1.0-0-dev). I'm having some trouble with libusb. I see questions about this all over the internet, but haven't yet found a solution that works.
Running cmake . appears to work fine:
meowmeow#kittytown:~/code/ttwatch$ cmake .
-- Enabled daemon function
-- Found libusb-1.0:
-- - Includes: /usr/include/libusb-1.0
-- - Libraries: /usr/lib/x86_64-linux-gnu/libusb.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/meowmeow/code/ttwatch
But running make shows that libusb is not being located properly:
meowmeow#kittytown:~/code/ttwatch$ make
[ 42%] Built target libttbin
[ 42%] Built target libttwatch
[ 42%] Built target ttbincnv
[ 42%] Built target ttbinmod
[ 42%] Built target manifest
Linking CXX executable ttwatch
CMakeFiles/ttwatch.dir/src/ttwatch.c.o: In function `main':
/home/meowmeow/code/ttwatch/src/ttwatch.c:1618: undefined reference to `libusb_init'
/home/meowmeow/code/ttwatch/src/ttwatch.c:1796: undefined reference to `libusb_exit'
...
If I check /usr/includes/, I see libusb:
meowmeow#kittytown:~/code/ttwatch$ ls /usr/include/libusb-1.0/libusb.h
/usr/include/libusb-1.0/libusb.h
And dpkg shows:
meowmeow#kittytown:~/code/ttwatch$ dpkg -L libusb-1.0-0-dev
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/libusb-1.0.pc
/usr/lib/x86_64-linux-gnu/libusb-1.0.a
/usr/share
/usr/share/doc
/usr/share/doc/libusb-1.0-0-dev
/usr/share/doc/libusb-1.0-0-dev/copyright
/usr/include
/usr/include/libusb-1.0
/usr/include/libusb-1.0/libusb.h
/usr/lib/x86_64-linux-gnu/libusb-1.0.so
/usr/share/doc/libusb-1.0-0-dev/README
/usr/share/doc/libusb-1.0-0-dev/changelog.Debian.gz
meowmeow#kittytown:~/code/ttwatch$ dpkg -L libusb-1.0-0
/.
/lib
/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu/libusb-1.0.so.0.1.0
/usr
/usr/share
/usr/share/doc
/usr/share/doc/libusb-1.0-0
/usr/share/doc/libusb-1.0-0/README
/usr/share/doc/libusb-1.0-0/copyright
/usr/share/doc/libusb-1.0-0/changelog.Debian.gz
/lib/x86_64-linux-gnu/libusb-1.0.so.0
The file ttwatch/includes/libttwatch.h includes libusb as #include <libusb.h>, and I've tried modifying that to #include <libusb-1.0/libusb.h>, in hopes of better matching my /usr/includes/ files, but that didn't change the error output.
Any help would be greatly appreciated!
EDIT:
Using make VERBOSE=1does show -lusb, and not -lusb-1.0:
...
/usr/bin/c++ -g CMakeFiles/ttwatch.dir/src/ttwatch.c.o CMakeFiles/ttwatch.dir/src/log.c.o CMakeFiles/ttwatch.dir/src/options.c.o CMakeFiles/ttwatch.dir/src/json.c.o CMakeFiles/ttwatch.dir/src/download.c.o CMakeFiles/ttwatch.dir/src/firmware.c.o CMakeFiles/ttwatch.dir/src/misc.c.o CMakeFiles/ttwatch.dir/src/get_activities.c.o CMakeFiles/ttwatch.dir/src/update_gps.c.o CMakeFiles/ttwatch.dir/src/set_time.c.o -o ttwatch -rdynamic libttwatch.a libttbin.a -lusb -lssl -lcrypto -lcurl
And libusb.so appears to exist:
meowmeow#kittytown:~/code/ttwatch$ dpkg-query -S /usr/lib/x86_64-linux-gnu/libusb.so
libusb-dev: /usr/lib/x86_64-linux-gnu/libusb.so
I tried uninstalling libusb-dev (sudo apt-get remove libusb-dev) and installed libusb-1.0 (sudo apt-get install libusb-1.0) to see if that would solve the issue. I now have a /usr/lib/x86_64-linux-gnu/libusb-1.0.so (note the 1.0) instead, but am now getting this from make:
make[2]: *** No rule to make target /usr/lib/x86_64-linux-gnu/libusb.so', needed by ttwatch'. Stop.
I was not aware that Debian has the packages libusb-dev and
libusb-1.0-dev. From the package information I cannot tell why there are 2
packages for the same library, perhaps libusb-dev is an older version with a
different API and other packages might still have that as a dependency. So
removing the package might not be a good idea, unless you don't care/need
packages depending on libusb-dev, in which case you can do apt-get purge
libusb-dev && apt-get autoremove. Be ware that this might uninstall
packages that you need. So do it only if you know what you are doing.
I did not expect that Debian allows you to install both packages at the same
time, but this could be if the APIs of both libraries are different and don't
conflict with each other.
This seems to confuse cmake, which somehow cannot handle when both libraries
are simultaneously installed. I've gone through the issues page and I
haven't found an issue relating to that. So if you cannot manage to build it,
I'd suggest that you go to the issue page, if you don't have an github
account, create one and leave a bug report about building the package when
libusb-dev and libusb-1.0-dev are simultaneously installed.
Another option would be to make a small modification in the file cmake_modules/FindLibUSB.cmake before you do
$ mkdir build && cd build
$ cmake ..
Find the line find_library(LIBUSB_1_LIBRARY, on the current stable version it is line 62. The next line is NAMES
and the next line is usb-1.0 usb. Remove the usb from that, so that
find_library only searches for libusb-1.0. Save the file and then you can do
$ mkdir build && cd build
$ cmake ..
This should fix the problem.

How to Install Wt into a Custom Folder Without "fatal error: Wt/WApplication: No such file or directory"

I'm new to Wt and c++ and I just installed the Wt webframework on Ubuntu 16.04 LTS into a custom folder in my home directory. I cannot install or build any software into the /usr diretories of this computer. Even if I could, the PPA hasn't been active for 2 1/2 years, and the official Ubuntu installation instructions are also outdated. Aptitude no longer ships with Ubuntu and will eventually be discontinued.
I compliled and installed everything successfully, yet when I try to compile the Hello World example I get the following error:
g++ -o hello hello.cpp -lwt -lwthttp
fatal error: Wt/WApplication: No such file or directory
Here are my installation steps:
Boost:
wget https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.bz2
tar --bzip2 -xf boost_1_65_1.tar.bz2
cd boost_1_65_1
./bootstrap.sh --prefix=../myfolder
sudo ./b2 install --prefix=../myfolder
CMake:
wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz
tar -xvzf cmake-3.9.2.tar.gz
cd cmake-3.9.2
./configure --prefix=../myfolder
make
sudo make install
vim .profile
export PATH=$PATH:/home/ubuntu/myfolder/bin
Wt:
git clone https://github.com/emweb/wt.git
cd wt
cmake -DCMAKE_INSTALL_PREFIX:PATH=../myfolder .
-- Generating done
-- Build files have been written to: /home/ubuntu/myfolder
make
sudo make install
make -C examples
Since I'm lumping everything together in /myfolder I did not use the /build folder per the Wt installation instructions. The libwt and libboost libraries are in /myfolder/lib. I assumed all of the linking was taken care of during installation.
Any thoughts? Thanks in advance.
You have to tell your compiler to look for includes and libraries in the right folders, so instead of:
g++ -o hello hello.cpp -lwt -lwthttp
Try:
g++ -o hello hello.cpp -I/home/ubuntu/myfolder/include -L/home/ubuntu/myfolder/lib -lwt -lwthttp
Note that when you run your application, you'll also have to make sure that it can find the dynamic libs (.so files) it needs. You could do this:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/ubuntu/myfolder/lib"

How to compile Box2D in Linux?

Compiling the Box2d Tesbed is supposed to be simple:
from iforce2d:
Download the Box2D source code archive from here. If you want to use the terminal all the way, you could also do this (if wget is not available, use yum to install it):
wget http://box2d.googlecode.com/files/Box2D_v2.1.2.zip
Use the following commands to unzip and build it.
[...]
unzip Box2D_v2.1.2.zip
cd Box2D_v2.1.2/Box2D/Build
cmake ..
make
( These instructions are pretty old, I did get my source with git clone https://github.com/erincatto/Box2D.git )
Running cmake .. from Box2D/Build in the freshly cloned directory causes multiple errors :
CMake Error at Testbed/CMakeLists.txt:84 (add_executable):
Cannot find source file:
Framework/imgui.h
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: Cannot determine link language for target "glfw".
CMake Error: CMake can not determine linker language for target: glfw
Of course, make fails:
[ 42%] Building CXX object Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Body.cpp.o
/home/cabri/Documents/Box2D/Box2D/Box2D/Dynamics/b2Body.cpp: In member function ‘void b2Body::DestroyFixture(b2Fixture*)’:
/home/cabri/Documents/Box2D/Box2D/Box2D/Dynamics/b2Body.cpp:216:17: error: ‘nullptr’ was not declared in this scope
if (fixture == nullptr)
^
Box2D/CMakeFiles/Box2D.dir/build.make:566: recipe for target 'Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Body.cpp.o' failed
make[2]: *** [Box2D/CMakeFiles/Box2D.dir/Dynamics/b2Body.cpp.o] Error 1
CMakeFiles/Makefile2:85: recipe for target 'Box2D/CMakeFiles/Box2D.dir/all' failed
make[1]: *** [Box2D/CMakeFiles/Box2D.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
Multiple similar questions can be found on these sites, but none has an answer. I know I can install box2d with
sudo apt-get install libox2d but I'd like to have the testbed as well.
How can this be done ?
Short answer...
yes this can be built, rollback your git clone of Box2D until the build doesn't fail.
Long answer...
Seems you've encountered two separate problems:
Not finding the imgui.h file.
The introduction of nullptr to the Git source tree which requires C++11 or newer language acceptance from the compiler.
Regarding problem 1, there's been an issue filed about that back at the beginning of February 2017: issue 433. Regarding problem 2, there's also been an issue filed for this back in June 2016: issue 414.
While I did not see a resolution on GitHub for problem 1, problem 2 apparently is resolvable by applying pull request #412. You should also be able to resolve problem 2 by having your compiler accept C++11 (or newer).
As for resolving problem 1, you can roll back your git clone of Box2D until the Testbed can be built. If you rollback far enough, that should also resolve problem 2 (without needing to do anything else). Information on how to do the reversion can be found at the SO question of How to revert Git repository to a previous commit?.
Ubuntu 17.10 Testbed
The major annoyance is that you currently need premake5, which is yet in alpha and therefore not in Ubuntu:
cd
git clone https://github.com/premake/premake-core
cd premake-core
git checkout v5.0.0-alpha12
make -f Bootstrap.mak linux
cd
git clone https://github.com/erincatto/Box2D
cd Box2D
git checkout f655c603ba9d83f07fc566d38d2654ba35739102
cd Box2D
~/premake-core/bin/release/premake5 gmake
cd Build/gmake
make
# Must be run from there because of a ttf font is at that reative path. GDB told me that. :-)
cd ../../Testbed
../Build/gmake/bin/Debug/Testbed
This builts the .a static library under Build/gmake/bin/Debug.
https://github.com/erincatto/Box2D/issues/387#issuecomment-219168623 gives some insight on the chaotic history of the build system.
First CMake was used, but Erin though premake was better, then premake lost support and the project stuck to Visual Studio + Xcode config files, then the premake project came back from the dead and was reinstated. When will they switch to CMake, which is infinitely portable, and will be forever supported? :-)
Shared library
The steps are the exact same, but first clean up the old static binaries:
git clean -xdf :/
and then before running premake5, apply the following patch to Box2D:
diff --git a/Box2D/premake5.lua b/Box2D/premake5.lua
index b937866..f666651 100644
--- a/Box2D/premake5.lua
+++ b/Box2D/premake5.lua
## -23,7 +23,7 ## workspace "Box2D"
buildoptions { "-std=c++11" }
project "Box2D"
- kind "StaticLib"
+ kind "SharedLib"
language "C++"
files { "Box2D/**.h", "Box2D/**.cpp" }
includedirs { "." }
The testbed still runs as before, but if you move the shared library it stops working as expected.
TODO clean system-wide installation. Manually copying the .so and headers into appropriate paths should work... but not much fun.
CMake revived
So simple, so much better.
Box2D/Box2D/CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
set (CMAKE_CXX_STANDARD 11)
file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "Box2D/*.cpp")
include_directories(${CMAKE_SOURCE_DIR})
add_library(Box2D SHARED ${SOURCES})
target_include_directories(Box2D PUBLIC ${CMAKE_SOURCE_DIR})
set(HELLO_SOURCES HelloWorld/HelloWorld.cpp)
add_executable(hello ${HELLO_SOURCES})
target_link_libraries(hello PRIVATE Box2D)
Then:
cd Box2D/Box2D
mkdir build
cd build
cmake ..
make
./hello
For now, I'll be tracking Box2D as a submodule and using this method for my projects I think, here is an example: https://github.com/cirosantilli/sdl-box2d
find compile static library
This might also be useful if you don't care about OS, and don't want to install premake:
cd Box2D/Box2D/Box2D
find . -iname '*.cpp' | xargs g++ -c -I../
ar rcs libBox2D.a *.o
g++ -I.. ../HelloWorld/HelloWorld.cpp libBox2D.a
./a.out
If you have the most recent commit from the Box2D repo checked out, you can restore the original CMake files by running this git command in the repository directory:
git checkout 05ee3c3c22af9ac1e5d88061d0b473f814c8210f^ \
Box2D/Box2D/Box2DConfig.cmake.in \
Box2D/Box2D/CMakeLists.txt \
Box2D/Box2D/UseBox2D.cmake \
Box2D/CMakeLists.txt \
Box2D/HelloWorld/CMakeLists.txt \
Box2D/Testbed/CMakeLists.txt \
Box2D/glew/CMakeLists.txt \
Box2D/glfw/CMakeLists.txt
Since Box2D has started using C++11 features since this commit, so you will need to add this line to Box2D/CMakeLists.txt:
set (CMAKE_CXX_STANDARD 11)
If you only want the core library built, you're done; just run the following commands:
mkdir build
cd build
cmake -D BOX2D_BUILD_EXAMPLES=OFF ../Box2D
Testbed
If you want the Testbed, things get a bit more involved. The CMakeLists for Box2D's copy of GLFW seems to be completely broken. Open Box2D/CMakeLists.txt, and find these two lines:
add_subdirectory(glew)
add_subdirectory(glfw)
Replace them with the following. This will cause the build to use your system versions of the libraries, so you will need to have them installed:
find_package(GLEW REQUIRED)
if (GLEW_FOUND)
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})
endif()
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
Open Box2D/Testbed/CMakeLists.txt. At the top of the file, under set(Testbed_Framework_SRCS, remove the 4 lines referring to imgui and RenderGL3. Add the following lines in that section:
../imgui/imgui.h
../imgui/imgui.cpp
../imgui/imgui_draw.cpp
../imgui/imgui_impl_glfw_gl3.cpp
Scroll to the bottom and replace the glew and glfw lines with:
${GLEW_LIBRARIES}
${GLFW_STATIC_LIBRARIES}
Finally replace
file(COPY ../Build/Data DESTINATION ..)
with
file(COPY ./Data DESTINATION .)
At this point, the full library and testbed should be buildable:
mkdir build
cd build
cmake ../Box2D