C++ MsgPack unable to compile - c++

Am getting the following error when i tried to cmompile the code which uses the library
http://msgpack.org/ , i tried the first example in C++ section ( documentation of library )
g++ hello.cc -lmsgpack -o hello
/usr/local/lib/libmsgpack.so: undefined reference to `__sync_sub_and_fetch_4'
Any help is appreciable ..
g++ version details ..
$ g++ -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)

Please try updating your g++ compiler. Such error suggests that your compiler is too old and the code you are trying to compile is too new for it.
I am using g++ version 4.6.3 and there are no problems.

This one worked for me ...
Update your GCC tool-chain. Or try to add -march=pentium or -march=i486, etc.
#qehgt Thanks a lot :-)

Related

Specify thread model on ubuntu mingw (if possible)

Im running a program on linux with g++ and everything works fine. If i compile using x86_64-w64-mingw32-g++ it crashes with error: ‘std::thread’ has not been declared.
The part where my code crashed is fairly simple:
#include <thread>
int main()
{
int cores = std::thread::hardware_concurrency();
}
I figured out that mingw uses win32 threads, i want it to use posix threads. Version is:
:~$ x86_64-w64-mingw32-g++ -v
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libdir='/usr/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --with-headers=/usr/x86_64-w64-mingw32/include --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-lto --enable-threads=win32 --program-suffix=-win32 --program-prefix=x86_64-w64-mingw32- --target=x86_64-w64-mingw32 --with-as=/usr/bin/x86_64-w64-mingw32-as --with-ld=/usr/bin/x86_64-w64-mingw32-ld --enable-libatomic --enable-libstdcxx-filesystem-ts=yes --enable-dependency-tracking
Thread model: win32
gcc version 9.3-win32 20200320 (GCC)
As you can see thread model is win32, (how) can i change it? In the mingw include paths there is a 9.3-posix folder, but it seems it isnt used so far.
As you can see here you can:
I'm installing mingw-w64 on Windows and there are two options: win32 threads and posix threads.
Is that possible on linux aswell?
It seems that the package g++-mingw-w64-x86-64 provides two executables:
x86_64-w64-mingw32-g++-posix: which uses posix
x86_64-w64-mingw32-g++-win32: which uses win32
Using the first executable should solve your issue.

Homebrew gcc can't find omp.h on OS X

I've spent hours trying different solutions but nothing has worked so far.
I've installed gcc via Homebrew, and linked gcc to the Homebrew gcc. gcc -v returns this:
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/5.3.0/libexec/gcc/x86_64-apple-darwin14.5.0/5.3.0/lto-wrapper
Target: x86_64-apple-darwin14.5.0
Configured with: ../configure --build=x86_64-apple-darwin14.5.0 --prefix=/usr/local/Cellar/gcc/5.3.0 --libdir=/usr/local/Cellar/gcc/5.3.0/lib/gcc/5 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-5 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --with-build-config=bootstrap-debug --disable-werror --with-pkgversion='Homebrew gcc 5.3.0 --without-multilib' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --disable-multilib
Thread model: posix
gcc version 5.3.0 (Homebrew gcc 5.3.0 --without-multilib)
However, when I try to compile I get
This is make_MWA_Tools.sh
using $CFITSIO =
building LFILE & read_mwac utilities
cc -g -O -Wall -D_FILE_OFFSET_BITS=64 -fopenmp -c mwac_utils.c
mwac_utils.c:3:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
1 error generated.
make: *** [mwac_utils.o] Error 1
!!!!!!!!!!!!!!!!!!!!!!
build_lfiles/read_mwac make failed !
I've looked in gcc located under Cellar and found mop.h, but for some reason its not being included. Any help would be greatly appreciated.
Edit: I don't believe this is a duplicate question because I could not find another question that Installed gcc from Homebrew, linked 'gcc' to the homebrew gcc installation, and still couldn't find omp.h

access the string in one function with operator[] affects the output of the other function in C++

when compile the above function, it will print nothing. While if we comment out "char tmp = num[0]", it will print "===test==="
#include <iostream>
using namespace std;
void eval(string num)
{
char tmp = num[0];
}
int main()
{
int i;
cout<<"===test==="<<endl;
return 0;
}
I know it is something wrong in the implementation. I test it in Cygwin, with the following g++ version:
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/5.2.0/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with: /cygdrive/i/szsz/tmpp/gcc/gcc-5.2.0-1.x86_64/src/gcc-5.2.0/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-5.2.0-1.x86_64/src/gcc-5.2.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id
Thread model: posix
gcc version 5.2.0 (GCC)
But no such problem in my Ubuntu 14.04.
Could anyone give me an explanation? Really weird. Thanks.
===Updates:
and why I got -2 points for this question?
===Updates2:===
problem solved. We have to install all the related components (gcc-core, g++, libgcc, libsupc, libstdc++ ....) of 5.2.0 version
The problem is something I've seen before. You will find you have a warning about entry point. The linker defaults to the first function as the entry point if it can't determine it. Also, note that moving main() to the first function doesn't fix the problem as the entry point is called with different arguments and a different calling convention.
I'm not sure what you did wrong but it would help if you posted your compilation command.
g++ -o test.exe test.cpp
is the correct command to compile it; note that we must invoke it as ./test due to cygwin (current directory is not in PATH by default).

Access=stream is throwing a Fortran runtime error

I have a piece of code that works on my laptop but not on our Linux cluster. It's pretty straight forward.
open(11,file=trim(openfile),form='unformatted',access='STREAM')
throws a runtime error:
Fortran runtime error: Bad ACCESS parameter in OPEN statement
What is happening?
gcc was build as:
gfortran -v Using built-in specs. Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada
--enable-java-awt=gtk --disable-dssi --disable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix gcc version 4.1.2 20080704 (Red Hat 4.1.2-55)

GCC -v returns GCC 4.7.3 even though I unpacked 4.8.1?

so I went to this link Source Forge MinGW to download and install MinGW 4.8.1. (rev 5). I unpack it into C:\MinGW\mingw32. So I open command prompt (win 32 system) and run gcc -v and I get GCC is 4.7.3. This is the full output of gcc -v:
C:\MinGW\mingw32>gcc -v Using built-in specs. COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/4.7.3/lto-wrapper.exe
Target: i686-pc-cygwin Configured with:
/cygdrive/i/szsz/git/cygwin-ports-gcc/gcc-4.7.3-1/src/gcc-4.7.3
/configure
--srcdir=/cygdrive/i/szsz/git/cygwin-ports-gcc/gcc-4.7.3-1/src/gcc-4.
7.3 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --lib execdir=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --d atarootdir=/usr/share --docdir=/usr/share/doc/gcc -C --build=i686-pc-cygwin --ho st=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix
--without-li bintl-prefix --enable-shared --enable-shared-libgcc --enable-static --enable-ver sion-specific-runtime-libs --enable-bootstrap --disable-__cxa_atexit --with-dwar f2 --with-arch=i686 --with-tune=generic --disable-sjlj-exceptions --enable-langu ages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-threads= posix --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmat h-support --enable-libssp --enable-libada --enable-libjava --enable-libgcj-subli bs --disable-java-awt --disable-symvers
--with-ecj-jar=/usr/share/java/ecj.jar -
-with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-ppl --with-sy stem-zlib : (reconfigured) /cygdrive/i/szsz/git/cygwin-ports-gcc/gcc-4.7.3-1/src
/gcc-4.7.3/configure
--srcdir=/cygdrive/i/szsz/git/cygwin-ports-gcc/gcc-4.7.3-1/ src/gcc-4.7.3 --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin
--sbindir=/usr/ sbin --libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdi r=/etc --datarootdir=/usr/share --docdir=/usr/share/doc/gcc -C --build=i686-pc-c ygwin --host=i686-pc-cygwin --target=i686-pc-cygwin --without-libiconv-prefix -- without-libintl-prefix --enable-shared --enable-shared-libgcc --enable-static -- enable-version-specific-runtime-libs --enable-bootstrap
--disable-__cxa_atexit -
-with-dwarf2 --with-arch=i686 --with-tune=generic --disable-sjlj-exceptions --en able-languages=ada,c,c++,fortran,java,lto,objc,obj-c++
--enable-graphite --enabl e-threads=posix --enable-libgomp --disable-libitm --enable-libquadmath --enable- libquadmath-support --enable-libssp --enable-libada --enable-libjava --enable-li bgcj-sublibs --disable-java-awt --disable-symvers
--with-ecj-jar=/usr/share/java /ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-ppl --with-system-zlib Thread model: posix gcc version 4.7.3 (GCC)
C:\MinGW\mingw32>
I would like to know why it unpacked an earlier version and how to fix this. Apparently C::B see's it as an earlier build too! It really baffles me O.o
Also, the prompt returns that threads use Posix when it should be Win32, again really rattling my brain here.
If any one can point to some links, or clear any of this up it would be greatly appreciated!
What you unpacked, and what the OS presents when you call the program, need not be the same thing. Did you do a rehash? Confirm that the path is the same? Or is the new version at a later point in the path? You might want to alias the gcc command to the version you want. Type which gcc to see where the OS thinks the "current version" is located - that should help. EDIT I realize the which command may not work in windows (just noticed the C: drive letter) but the main point about paths is still valid.