How to compile Box2D in Linux? - c++

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

Related

Build of opencv4 for c++ using cmake failing after upgrading to macOS Catalina

hi I am trying to build opencv4 from source using cmake (following https://thecodinginterface.com/blog/opencv-cpp-vscode/). I updated my macOS to 10.15 and installed the latest xcode. I git cloned repositories and make a build directory as below and I then try to configure cmake:
$ mkdir opencv
$ cd opencv
$ git clone https://github.com/opencv/opencv.git
$ cd opencv
$ git checkout tags/4.2.0
$ cd ..
$ git clone https://github.com/opencv/
$ cd opencv_contrib
$ git checkout tags/4.2.0
$ cd ..
$ cd build_opencv
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=../install \
-D INSTALL_C_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ../opencv
I get the below errors and it seems that it's trying to find this non-existent path:
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework"
I have updated my mac version to 10.15 but it seems to be searching for a path under MacOSX10.14. I've looked online but I can't seem to find any suggestions?
CMake Error in /usr/local/include/opencv/build_opencv/CMakeFiles/CMakeTmp/CMakeLists.txt:
Imported target "VTK::RenderingOpenGL2" includes non-existent path
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
CMake Error in /usr/local/include/opencv/build_opencv/CMakeFiles/CMakeTmp/CMakeLists.txt:
Imported target "VTK::RenderingOpenGL2" includes non-existent path
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
CMake Error in /usr/local/include/opencv/build_opencv/CMakeFiles/CMakeTmp/CMakeLists.txt:
Imported target "VTK::RenderingOpenGL2" includes non-existent path
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework"
in its INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:
* The path was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and references files it does not
provide.
CMake Error at cmake/OpenCVDetectVTK.cmake:73 (try_compile):
Failed to generate test project build system.
Call Stack (most recent call first):
CMakeLists.txt:767 (include)
-- Configuring incomplete, errors occurred!
Download and install
Command Line Tools for XCode 12
from the apple developer tools downloads.
It used to work that you could execute xcode-select --install and it would do it for you, however, there is now an error occurring where it says that it cannot find the package or something like that. Therefore, this approach has to be taken.

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.

CMake is not found when running through make

I'm trying to build https://github.com/AlbertWerner/cryptonotecoinwallet and facing an issue.
According to the README of the repo, I can run cmake command and it completes without any errors. But then, when I run make, it gives me the below error.
$ make
make: /usr/bin/cmake: Command not found
make: *** [Makefile:5138: cmake_check_build_system] Error 127
I'm using MSYS on Windows and here are the corresponding details.
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/mingw32/bin
$ which cmake
/mingw32/bin/cmake
Seems like it's looking for cmake in the wrong path.
Makefile
cmake_check_build_system:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system # <== Line 5139
I'm not sure what's wrong. Please help me out.
Thanks.
Make sure that you launch MSYS2 using the mingw32.exe executable at the top level of your MSYS2 installation, and that you use that environment when you first run cmake. If you ran CMake in a different environment, remove all the files it created. The commands for running cmake and building the project should be something like this, assuming the developers have set it up in a reasonable way:
mkdir build
cd build
cmake .. -G"MSYS Makefiles"
make
I didn't try this myself because I am wary of running random code from the internet, but I found this note in the CMakefile indicating that the developers do not support MSYS2:
if (WIN32)
if (NOT MSVC)
message(FATAL_ERROR "Only MSVC is supported on this platform")
endif ()
...
So you will have to spend some effort on porting the Windows-specific code in this program to GCC if you really want to do this.

How can I statically link Arrow when building parquet-cpp?

From the parquet-cpp home page:
By default, Parquet links to Arrow's shared libraries. If you wish to statically-link the Arrow symbols instead, pass -DPARQUET_ARROW_LINKAGE=static.
I do want to statically link Arrow, because I want to use my program on other servers that won't have Arrow installed. I tried -DPARQUET_ARROW_LINKAGE=static, but I get an error about "missing transitive dependencies":
# cmake -DPARQUET_BUILD_TESTS=Off -DCMAKE_BUILD_TYPE=Release -DPARQUET_MINIMAL_DEPENDENCY=ON -DPARQUET_ARROW_LINKAGE=static .
-- The C compiler identification is GNU 4.8.5
...
-- [ /usr/local/share/cmake-3.9/Modules/FindBoost.cmake:1717 ] Boost_FOUND = 1
-- Boost version: 1.55.0
...
-- THRIFT_HOME:
-- Thrift compiler/libraries NOT found: (THRIFT_INCLUDE_DIR-NOTFOUND, THRIFT_STATIC_LIB-NOTFOUND). Looked in system search paths.
-- Thrift include dir: /root/tmp/parquet-cpp-master/thrift_ep/src/thrift_ep-install/include
-- Thrift static library: /root/tmp/parquet-cpp-master/thrift_ep/src/thrift_ep-install/lib/libthrift.a
-- Thrift compiler: /root/tmp/parquet-cpp-master/thrift_ep/src/thrift_ep-install/bin/thrift
-- Checking for module 'arrow'
-- No package 'arrow' found
-- Could not find the Arrow library. Looked for headers in , and for libs in
-- Building Apache Arrow from commit: 501d60e918bd4d10c429ab34e0b8e8a87dffb732
-- CMAKE_CXX_FLAGS: -O3 -DNDEBUG -Wall -std=c++11
-- Found cpplint executable at /root/tmp/parquet-cpp-master/build-support/cpplint.py
CMake Error at CMakeLists.txt:515 (message):
Missing transitive dependencies for Arrow static linking
So I found the code that generates the error:
if (NOT DEFINED ENV{BROTLI_STATIC_LIB_ENC} OR
NOT DEFINED ENV{BROTLI_STATIC_LIB_DEC} OR
NOT DEFINED ENV{BROTLI_STATIC_LIB_COMMON} OR
NOT DEFINED ENV{SNAPPY_STATIC_LIB} OR
NOT DEFINED ENV{ZLIB_STATIC_LIB} OR
NOT DEFINED ENV{LZ4_STATIC_LIB} OR
NOT DEFINED ENV{ZSTD_STATIC_LIB})
message(FATAL_ERROR "Missing transitive dependencies for Arrow static linking")
But that doesn't really help me, since I don't know what to do to get those environment variable defined.
Do I need to compile Arrow and install myself first? (I would rather have parquet-cpp do it for me.)
I arranged a script to download dependencies sources, set the environment variables and run your cmake line at the end. Just change the DEPDIR variable value, setting it to a directory of choice.
#!/bin/bash
CMKDIR=$PWD
DEPDIR=/tmp
cd $DEPDIR
#snappy
git clone https://github.com/google/snappy.git
cd snappy
mkdir build
cd build
cmake ..
make
export SNAPPY_STATIC_LIB=$DEPDIR/snappy/build/libsnappy.a
cd $DEPDIR
#brotli
git clone https://github.com/google/brotli.git
cd brotli
mkdir out
cd out
../configure-cmake
make
export BROTLI_STATIC_LIB_ENC=$DEPDIR/brotli/out/libbrotlienc-static.a
export BROTLI_STATIC_LIB_DEC=$DEPDIR/brotli/out/libbrotlidec-static.a
export BROTLI_STATIC_LIB_COMMON=$DEPDIR/brotli/out/libbrotlicommon-static.a
cd $DEPDIR
#zlib
git clone https://github.com/madler/zlib.git
cd zlib
./configure
make
export ZLIB_STATIC_LIB=$DEPDIR/zlib/libz.a
cd $DEPDIR
#lz4
git clone https://github.com/lz4/lz4.git
cd lz4
make
export LZ4_STATIC_LIB=$DEPDIR/lz4/lib/liblz4.a
cd $DEPDIR
#zstd
git clone https://github.com/facebook/zstd.git
cd zstd
make
export ZSTD_STATIC_LIB=$DEPDIR/zstd/lib/libzstd.a
cd $CMKDIR
cmake -DPARQUET_BUILD_TESTS=Off -DCMAKE_BUILD_TYPE=Release -DPARQUET_MINIMAL_DEPENDENCY=ON -DPARQUET_ARROW_LINKAGE=static
This script is very simple but should be effective. Just copy it in a new file (in the same CMakeLists.txt directory), give the file the execute permissions (i.e. sudo chmod +x filename) and execute it like this:
./filename.sh
About the fPIC option issue, you have to edit some files:
snappy: add this line in CMakeLists.txt, at the beginning, after the first two lines:
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
lz4 and zstd: edit the Makefile in lib sub-directory, after this line
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
add this line:
CFLAGS += -fPIC
zlib: edit the Makefile, after this line
CFLAGS=-O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
add this line:
CFLAGS += -fPIC
brotli: as far as I can see from make output, the option is already set.
Before running make again, execute this script:
#!/bin/bash
DEPDIR=/tmp
cd $DEPDIR/snappy/build
cmake ..
make clean
make
cd $DEPDIR/lz4
make clean
make
cd $DEPDIR/zstd
make clean
make

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

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.