There is a specific program i need to run using c++11 libraries offered by gcc-4.8 and higher. The remote HPC on which i am trying to run the program has gcc-4.6.1. I was able to install the gcc-4.8.2 version on the HPC in a user specified directory, say
/share/user/gccInstall
(gccInstall has the /bin and /lib (etc) folders you get after installation)
I need to switch to this version for compiling my program. I tried using update-alternatives --config gcc, but it does not return anything.
Can anyone help me solve this!
EDIT:
Was able to change the gcc version using the following commands:
setenv PATH /share/user/gccInstall/bin
setenv LD_LIBRARY_PATH /share/user/gccInstall/lib
Now gcc --version returns 4.8.2.
But encountered another error while compiling:
g++: error trying to exec 'as': execvp: No such file or directory
what am i missing?
Many Thanks.
If you have a different version of g++ that you want to use then make sure you're getting the right one according to your $PATH or else specify the full path to the g++ you want. The other thing to be aware of is that you will probably need to update the $LD_LIBRARY_PATH environment variable to get the necessary libraries from your new gcc installation.
What exactly is the problem you're having? Can you compile but not run? Does compilation fail? Do you have any error messages you can share?
Assuming as you say that your new GCC installation is
under /share/user/gccInstall then if you add the option
-B/share/user/gccInstall
to each invocation of g++ or gcc then it will have this
effect:
-Bprefix
This option specifies where to find the executables, libraries, include files, and data files of the compiler itself.
(from Options for Directory Search)
This should help, and will perhaps be enough.
Related
So i have written an app in c++ to download mp3s from the web using a list.
It uses libcurl to download them.
I am on linux. Compiling with
g++ main.cpp -lcurl -o word2mp3
works fine.
I need an windows executable, but running
x86_64-w64-mingw32-g++ main.cpp -o wordtest returns the
undefined reference to `__imp_curl_easy_init'
followed by the other curl functions. Adding -lcurl to the command also gives an error saying that curl isn't found.
I've tried and searched everywhere, no luck, I'm a beginner.
Link to my github repo: https://github.com/sharpclone/Word2Mp3
You need to compile libcurl with MinGW, or find a precompiled one. The one you installed to compile your app on Linux was compiled with a Linux compiler, and wouldn't work with MinGW.
MSYS2 repos have a bunch of precompiled libraries for different flavors of MinGW.
I've made a script to automatically download those libraries, since their package manager only works on Windows.
git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2
make install _gcc _curl
env/shell.sh
cd ..
git clone https://github.com/sharpclone/Word2Mp3
cd Word2Mp3/
win-clang++ main.cpp -lcurl -o word2mp3
This doesn't rely on an external MinGW installation, and only requires Clang (and LLD) to be installed (a regular Clang for Linux, unlike GCC you don't need to install a special version of it to cross-compile).
Or, if you prefer your existing compiler, you can stop at make install _curl, then manually specify the path to the installed library, normally -Lquasi-msys2/root/mingw64/lib. You just need to make sure the MSYS2 repo you're using matches your compiler.
To fix the undefined reference warning, you need to link to the required library, so the -lcurl is correct and required.
If the compiler cannot find the library, you need to tell him where to find it, that can be done by passing -L followed by the path to the library (that would be the path to the directory where libcurl.dll.a is in).
The order of the parameters can also be relevant, I think the correct order would be -L <path> -lcurl.
After upgrading my MacBook Pro to OS X 11.1 Big Sur, I am unable to get compilation of c++ programs using gcc to work.
I am using CLion with CMake, and I get the following error when reloading the CMake configuration
ld: library not found for -lgcc_s.10.4
The things that I have tried are installing Xcode, it installed without error.
I have tried to create a symlink as suggested here https://github.com/Paxa/fast_excel/issues/33
$ cd /usr/local/lib
$ sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.4.dylib
It appears that the library libSystem.B.dylib is not present. Some sites mention that the libraries starting with Big Sur reside in some "shared cache", which I have no idea of what it is and how to access it, let alone make ld access it on its own.
Any suggestions on how to solve this are very welcome. Thank you!
According to this answer you should use: g++-10 -o main main.cpp
The correct path of brew installed g++ in MacOS is:
$ which g++-10
> /usr/local/bin/g++-10
--
$ which g++
> /usr/bin/g++ //this is alias of clang (same for lyb)
If you use CMakeLists.txt file you will configure it like this:
set(CMAKE_CXX_COMPILER "/usr/local/bin/g++-10" CACHE STRING "C compiler" FORCE)
set(CMAKE_C_COMPILER "/usr/local/bin/gcc-10" CACHE STRING "C++ compiler" FORCE)
set(CMAKE_CXX_STANDARD 17)
In general, gcc tends not to work on more recent versions of Mac OS. The solution is to use the build in C/C++ compilers. To automatically use these, instead of GCC, set these environment variables:
CC="clang"
CXX="clang++"
This will use the built in Mac compilers. Once doing this, I have yet to run into an issue with compiling that wasn't due to the actual code being compiled.
Thank you for all the answers highlighting different things that could solve the issue. What ended up working was to run brew reinstall gcc, and pointing CLion (or plainly CMake as Mike mentioned) to use the correct compiler (something that I had already done, but I want to mention it here if anyone else finds this question and has the same problem), the paths that I use are
/usr/local/Cellar/gcc/10.2.0/bin/gcc-10
/usr/local/Cellar/gcc/10.2.0/bin/g++-10
These paths are actually just the explicit locations that are linked from
/usr/local/bin/g++-10
/usr/local/bin/gcc-10
Also, as Matt Braunstein mentioned, it is possible to use clang that is supplied with Mac OS X, something I did while figuring out how to solve my issues with gcc.
My thoughts on the problem is that somehow, installing gcc with homebrew didnt install everything needed as it appeared to already be installed from a previous version, the reinstall command seemed to rectify this.
Again, thank you for the answers that helped me find this solution, and possible workarounds.
I spent hours trying to solve this compilation problem with cmake, the original statement in CMakeLists.txt for library linkage is!
link_directories(/usr/local/lib)
target_link_libraries(Program libsndfile.dylib)
With error message after make:
ld: library not found for -lsndfile
The solution that works is to add the entire path like this:
target_link_libraries(Program /usr/local/lib/libsndfile.dylib)
There is no need to have this in Ubuntu, but somehow the new MacOS requires it.
I just installed OpenCV-3.4.1 on Ubuntu 18.04. I am able to compile my C++ files only when I run the g++ command with pkg-config --cflags --libs opencv
Is it possible for me to compile the c++ file without using these additional flags
How can I tell g++ to automatically look at /usr/include/opencv for the .h files everytime
For adding to the include path see this question: How to add a default include path for GCC in Linux?
A better solution however is to write a shell script to compile your code rather than having to type in the command line every time.
The best solution is to use a proper build system which will save you a lot of pain in the future, just a few of the many available options:
GNU make
cmake
google gyp
google gn
ninja
I want to create a .exe of ndpiReader.c demo program that comes with nDPI library. I was successful to compile it on Ubuntu using commands specified on their github page as bellow:
./autogen.sh
./configure
make
I have tried to cross compile it using GCC inside Ubuntu but I wasn't successful. I also tried to use the pcapExample.sln to compile it in Visual Studio 2012, but I keep getting error messages like:
Error 29 error C1083: Cannot open include file: 'ndpi_api.h': No such file or directory
Although ndpi_api.h and all other files that I get this error for already are listed in the project solution explorer.
Has anyone actually been able to make a win32 executable out of this ndpiReader.c file? If yes, please specify the steps, requirements, or a link.
nDPI lib is hosted here: https://github.com/ntop/nDPI
ndpiReader.c is hosted here: https://github.com/ntop/nDPI/tree/dev/example
pcapExample.sln is hosted here: https://github.com/ntop/nDPI/tree/dev/example/Win32
I saw from your other questions that you had already tried to compile this with CYGWIN and ran into a number of problems.
Here’s a step-by-step guide I just used to compile nDPI (including the ndpiReader.exe example):
Install CYGWIN:
Accept the default directories, and pick a mirror.
At the Select Packages step, expand the Devel category, and select the following developer packages to install:
autoconf
autoconf2.5
automake
automake1.15
binutils
cmake
cygwin-devel
gcc-core
gcc-tools-epoch2-autoconf
gcc-tools-epoch2-automake
libtool
make
pkg-config
w32api-headers
w32api-runtime
Install libpcap under CYGWIN:
Download and unpack the Winpcap Developer's pack.
Copy libpacket.a and libwpcap.a from WpdPack\Lib\ to cygwin\lib\
In cygwin\lib, copy libwpcap.a to libpcap.a
In cygwin\usr\include, create a pcap directory
Copy all headers from WpdPack\Include to cygwin\usr\include\pcap
I'm sure you've installed winpcap already as part of everything else you've tried, but double-check that the necessary (packet.dll and wpcap.dll) libraries are already in cygwin\c\WINDOWS\system32.
Now you've got all the necessary tools and libraries to compile nDPI on Windows!
Building nDPI
Download and unpack nDPI again in a clean directory, so you don't get tripped up by any issues from the previous build you tried.
Open a CYGWIN terminal, and cd into the nDPI directory.
Run autogen.sh
./autogen.sh
This should complete without any errors.
If it stops with "somepackage is missing: please install it and try again," you've missed installing a CYGWIN package that is needed to build the source.
If it stops with "Missing libpcap(-dev) library," double-check the previous steps you did to copy libpcap.a in cygwin\lib.
autogen.sh should start running the configure stage for you. (If it doesn't, or part of this stage fails, you can rerun configure after fixing any issue.)
./configure
After checking for a number of things, configure will end by creating a Makefile.
Build the nDPI library, by running make.
make
It will build the library, then try to build the examples, but fail because it can't find pcap.h
cd into the example directory, and manually compile ndpiReader.c by adding -I/usr/include/pcap to the command:
cd example/
gcc -DHAVE_CONFIG_H -I. -I.. -I../src/include -I/usr/include/pcap -g -O2 -c -o ndpiReader.o ndpiReader.c
I included my command as an example. If your compiler command is slightly different, just add -I/usr/include/pcap to what your Makefile had invoked.
Leave the example directory, and resume the make.
cd ..
make
This last step will link ndpiReader with the ndpi library, and create the executable you're looking for.
I'm trying to install cross-compiler using that tutorial .
I got stuck cross-compiling GCC version 4.9.1 using my native linux-GCC compiler. I occured an error during the installation and the solution is to build it in non-source directory. However, I have no idea how can I do it. I've read the documentation. However, it hasn't helped me.
I just want to install C++ and C version.
I haven't done this for ages but I think it means create a new empty directory and run configure from there, i.e. rather than
cd /usr/src/crosscompiler
./configure ...
do
mkdir /usr/src/crosscompiler-build
cd /usr/src/crosscompiler-build
/usr/src/crosscompiler/configure ...
which will then set up the build environment and make files in that new directory to use the source tree from the old directory. (If that doesn't work, you could try putting the empty directory inside the source tree, e.g. /usr/src/crosscompiler/build)
That all said, I thought a separate build directory has been the only way to build GCC for 10+ years, so I'm surprised the tutorial says anything different. You can build binutils into a separate path too, and there are ways of combining the GCC and binutils sources so that they can be built in one go too.