g++ no longer finding standard libraries OSX 10.6.8 - c++

no solutions I found on the internet have worked so far.
I am running OSX 10.6.8. I had previously been using the gnu compiler for C/C++ fine. I switched to XCode and have no problem with that but I would like to use the command line. However, after wiping my computer and restoring from a backup I was getting the error bash: g++ command not found.
First, I figured my $PATH got a bit wonky, so I tried to add in the correct path to the Path variable and now it recognizes g++ and tries to compile. But, I get this error now:
hello.cpp:3:20: error: iostream: No such file or directory
hello.cpp: In function ‘int main()’:
hello.cpp:8: error: ‘cout’ is not a member of ‘std’
Here is the Hello World! code:
#include <iostream>
int main ()
{
std::cout << "Hello World!";
return 0;
}
Solutions that have been posted online have mainly been problems with namespaces and #include statements but I do not believe this to be the error at this time.
when I type "which g++" into Terminal I get: /Developer/usr/bin/g++
and when I type g++ -v I get:
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5666.3~6/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
4.2.1 is an older version so if there is one thing I could change it would be switching to 4.7.2 which I found in usr/local/Cellar/gcc. I am not sure what Cellar is perhaps that comes from when I tried using homebrew to install gcc as I found on some other forum.
Thanks in advance, this is beyond my ken.

When you installed XCode, you simply forgot to check that little checkbox that says "install Unix command line utilities." When you do that, you'll get a fully working GCC installed in /usr/. The one installed in /Developer/ is not for command-line use. It's only for the XCode graphical IDE.

Related

Clang MacOs over command line does not work

I am fairly new to both MacOs and C++ and have a problem which is similar to the one described here but also no solution I find in the Internet works.
'fatal error: 'wchar.h' file not found' error with the new macos 11.3 update
If I try to compile the most simple c++ program on my machine via command line it does not work.
#include <iostream>
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
Since it used to work I probably broke something but don't know what
The simple test command I use is the following
clang -v --target=arm64 helloworld.cpp
Which results in a iostream not found error
if I now include the xcode include directory via
clang -v --target=arm64 -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ helloworld.cpp
The iostream error disappears and I get a wchar.h not found error
I removed xcode completely and reinstalled it but this seems to not help also does it not make a difference if I use clang or clang++.
With Clion and cmake it works but I do not know why
xcode-select version 2392
/usr/bin/clang
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
locate iostream.h
`/Library/Frameworks/Mono.framework/Versions/6.12.0/include/glib-2.0/gio/gfileiostream.h
/Library/Frameworks/Mono.framework/Versions/6.12.0/include/glib-2.0/gio/giostream.h
/opt/homebrew/Cellar/boost/1.76.0/include/boost/asio/basic_socket_iostream.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/iostreams/detail/iostream.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/math/cstdfloat/cstdfloat_iostream.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/nowide/iostream.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/typeof/std/iostream.hpp
/opt/homebrew/Cellar/glib/2.70.2/include/glib-2.0/gio/gfileiostream.h
/opt/homebrew/Cellar/glib/2.70.2/include/glib-2.0/gio/giostream.h
/opt/homebrew/Cellar/glib/2.70.2/include/glib-2.0/gio/gsimpleiostream.h
I had similar troubles building clang + llvm, then trying to use the newly built clang via
./build/bin/clang -std=c++20 <my_file>
gave me a
fatal error: 'iostream' file not found
What fixed it was if I compiled with the following instead:
./build/bin/clang -std=c++20 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk <my_file>
The fix largely comes from https://github.com/MaskRay/ccls/issues/191#issuecomment-556983460 and the discussion there

How to use MinGW with thread model posix on Anaconda

I am on Win10. I installed MinGW in Anaconda through
$ conda install -c anaconda mingw
But when I check with $ g++ -v
I see Thread model: win32, which does not support C++11 Thread class. As results when I run $ g++ myprogram.cpp -std=c++11 I got error
error: 'thread' is not a member of 'std'
Outside of Anaconda, I installed MinGW with installer from https://sourceforge.net/projects/mingw-w64/
When installing, choose "posix", and I got what I need.
So my question is, how to make this happen in Anaconda? I want to either
Set Anaconda's C++ compiler to the one outside (the one I installed with installer)
or, install a MinGW with posix in Anaconda.
I tried to find solutions online, the following helped me sorted out my questions. But I couldn't find a solution yet.
Troubles with POSIX program using threads with gcc
https://coderwall.com/p/rzkw6q/compile-c-code-with-c-11-threads
https://docs.conda.io/projects/conda-build/en/latest/resources/compiler-tools.html
The full output is as below. I appreciate for your help!
$ g++ -v
Using built-in specs.
COLLECT_GCC=C:\ProgramData\Anaconda3\Scripts\g++.bat\..\..\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/programdata/anaconda3/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../build/gcc/src/configure --target=x86_64-w64-mingw32 --prefix=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --with-sysroot=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --enable-languages=all,obj-c++ --enable-fully-dynamic-string --disable-multilib
Thread model: win32
gcc version 4.7.0 20111220 (experimental) (GCC)

Issue compiling a piece of open source software written in C++ on MacOS Sierra

I am trying to install a piece of open source software (AB3P) on MacOS Sierra. When I issue the command make I get this error: ld: library not found for -lops. The make command issued before the error is thrown is: g++ -g -o make_wordSet make_wordSet.o -L./Library -lops -D_POSIX_C_SOURCE=199506L -lpthread
I have the latest version of MacOS Sierra and Xcode + the Xcode command line developer tools (as of this writing). In addition gcc is installed, the command gcc --version returns:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
I am not sure how to approach the problem, any suggestions?
Get into Library folder, and make it first.
cd Library
make
There it will find the libops.a
On the updated version of the Ab3P as #ridoro1 mentioned, you need to make first NCBITextLib and edit the both Makefiles under Ab3P and also under Library.
First get into Library and make it. Then make Ab3P.
You need to download this library and compile it, then edit Makefile in the folder of this library and the Makefile in the lib folder inside it to point to NCBITextLib-master folder on your disk, after that You can compile the ABP3 library.

gfortran doesn't work after upgrading to El Capitan

I tried upgrading to El-Capitan and Xcode 7.0 and now gfortran doesn't work. Everytime I run gfortran, I get errors which google search doesn't seem to resolve so I'm asking stack overflow:
I'm trying to compile a minimal example program:
program hello
print *, "Hello World"
end program hello
When I run gfortran test.f
gfortran: warning: couldn’t understand kern.osversion ‘15.0.0
ld: library not found for -lgcc_s.10.4
collect2: error: ld returned 1 exit status
I'm not worried about the warning but the error of the ld is what's really bothering me. There's libgcc_s.10.4.tbd in the /usr/lib folder but it seems not be used by gfortran.
Can anyone help me resolve this as I would like to use gfortran for compiling some libraries?
MORE info: running gfortran -v outputs
gfortran: warning: couldn’t understand kern.osversion ‘15.0.0
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin12.2.0/4.8.0/lto-wrapper
Target: x86_64-apple-darwin12.2.0
Configured with: ../gcc-4.8-20120930/configure --enable languages=c++,fortran
Thread model: posix
gcc version 4.8.0 20120930 (experimental) (GCC)
The version of gfortran you have (4.8 installed into /usr/local) is not a version of GCC that apple would have distributed with Xcode (afaik they never made it to a version of GCC that new before switching to llvm, which has no Fortran front-end. The version of gcc distributed with Xcode 7 on el capitan identifies itself as:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
Your version came from somewhere else and is old enough to not know the x86_64-apple-darwin15.0.0 target. You'll need to update that compiler to get a working gfortran. Both macports and homebrew provide easy installations of various versions of gcc/gfortran on OS X el capitan, and I'd recommend using one of those to install gcc. Alternatively you can track down whatever you used to install gcc 4.8 before and see if they provide an update for el capitan.

Problems installing srilm 1.6.0 with llvm-gcc 4.x

The problem
I am trying to build SRI's Language Modeling tool, srilm version 1.6.0 on my mac, and coming across some fairly strange compilation problems ("strange" in that a few hours of Google-fu did not help), so I am turning to you to see if anyone sees how I can fix this.
I have already checked that I have the required dependencies and followed the install instructions as well as gone through the build troubleshooting section of the FAQ.
System Specifications
I have a pretty vanilla install of OS X, with some packages installed through homebrew. XCode 4.3.2 (latest version) is installed. Here are the other relevant system details.
OS version
Mac OS X 10.7.4
gcc -v printout
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin11.0.0/4.6.1/lto-wrapper
Target: x86_64-apple-darwin11.0.0
Configured with: ../gcc-4.6.1/configure --enable-languages=fortran,c++
Thread model: posix
gcc version 4.6.1 (GCC)
g++ -v printout
$ gcc -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin11.0.0/4.6.1/lto-wrapper
Target: x86_64-apple-darwin11.0.0
Configured with: ../gcc-4.6.1/configure --enable-languages=fortran,c++
Thread model: posix
gcc version 4.6.1 (GCC)
uname -a printout
$ uname -a
Darwin MacBook-Air.local 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr 9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64
The error itself
The following is the end of the output produced by running make World from the srlim top-level directory. Everything up until this point compiles fine in any of the following circumstances:
I run make World on its own.
I run make World MACHINE_TYPE=macosx
I run make World MACHINE_TYPE=macosx-m64 (specific makefile for 64bit processors)
I run make World MACHINE_TYPE=macosx-m32 (specific makefile for 32bit processors)
And the error that pops up is always the same (shown below).
stderr printout
$ make World
(...) # a bunch of stuff compiles with no errors or warnings
c++ -Wreturn-type -Wimplicit -DINSTANTIATE_TEMPLATES -DHAVE_ZOPEN -I/usr/include -I. -I../../include -DHAVE_ZOPEN -c -g -O2 -fno-common -o ../obj/macosx/LatticeIndex.o LatticeIndex.cc
LatticeIndex.cc:78:6: error: variable length array of non-POD element type
'NBestWordInfo'
makeArray(NBestWordInfo, roundedNgram, len + 1);
^
../../include/Array.h:93:33: note: expanded from macro 'makeArray'
# define makeArray(T, A, n) T A[n]
^
LatticeIndex.cc:126:4: warning: data argument not used by format string
[-Wformat-extra-args]
(float)ngram[0].start);
^
LatticeIndex.cc:128:4: warning: data argument not used by format string
[-Wformat-extra-args]
(float)(ngram[len-1].start + ngram[len-1].duration));
^
2 warnings and 1 error generated.
make[2]: *** [../obj/macosx/LatticeIndex.o] Error 1
make[1]: *** [release-libraries] Error 1
make: *** [World] Error 2
Any idea what could be going wrong? It seems to compile fine on some other people's macs in my department, and I've checked their makefiles for differences, but nothing popped up. No one here has any idea why the build fails, but we'd really appreciate it if you can help us out. Thanks in advance for any help you can provide me with! :-)
The problem is due to Apple using llvm-gcc/clang, which does not support variable length arrays. This problem can actually be addressed by modifying $SRILM/dstruct/src/Array.h, and has been noted and addressed in the upcoming release of srilm.
For the time being, on a mac, build srilm using g++ 4.2 instead, using the following command:
$ make MACHINE_TYPE=macosx-m64 CXX=g++-4.2 World
This builds srilm without problem on all my macs.