"g++" not found in PATH [mac/Eclipse/XCODE installed/CDT downloaded] - c++

I get this error when I try to build a c++ project, however I can run cpp apps in Xcode, I've downloaded CDT for Eclipse, so the compiler must be installed.
echo $PATH:
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
I'm using Mac, I've found posts saying download gcc or Xcode, or solutions for Windows, it's very frustrating that I can't find the answer for such an easy problem, so please… How can I set the PATH variable for my cpp projects in Eclipse?

This question should help. It looks like you need to install XCode command line tools separately to use compilers and build systems outside of XCode (e.g. on the command line or in Eclipse).

Related

Header Files not Working in CLion after Xcode update

Apple sent out an Xcode update today and little did I know it would mess with my all of my header files.
The header file I am attempting to use is time.h. I know the code if fully functional because an online C++ shell will run it fine but CLion is telling me Cannot find 'time.h'. When I attempt to run the program I receive the following:fatal error: 'wchar.h' file not found. This was odd because I was able to locate the wchar.h file.
As per this post, I have followed all the instructions to no avail. I have also checked the location of the Command Line Tools with xcode-select -p and received that they are in /Library/Developer/CommandLineTools, which seems to be correct. I have also checked that gcc is working and the correct version. Any time I try xcode-select --install at this point it just tells me that it is installed and check for updates if I think it is wrong. It also told me there were no updates.
The only other thing I can think of is that the compiler is also telling me the following:
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk' [-Wmissing-sysroot]
And after checking this directory, I noticed that my sdk is MacOSX 10.13 where the compiler was looking for 10.12. Also my SDK is just a 10 byte alias file that OS X tells me can't be found when I click on it?
I am really scratching my head on this one, I have re-installed Xcode already just as a last resort to no avail. Any help would be much appreciated.
You need to change the sdk your project is using. Go to your Target and look at the Build Settings. Set the Base SDK popup to "Latest Mac OS(...)" and you should be good to go.

Building C++ not working in OSX 10.9

Update:
I solved the problem in the end by reinstalling command line tools, as shown in this link.
Sorry for the trouble!
Initial question
I have just upgraded to OSX Mavericks and I cannot make the compiler work anymore.
I've been using gcc48 from macports with vim/sb2 and everything was working just fine. Now any library that I include gives tons of errors. I am not very experienced and I do not know what to do, or what to search for. I just want it to work like before. Here is what is says when compiling a basic "hello world" program:
In file included from /opt/local/include/gcc48/c++/bits/postypes.h:40:0,
from /opt/local/include/gcc48/c++/iosfwd:40,
from /opt/local/include/gcc48/c++/ios:38,
from /opt/local/include/gcc48/c++/ostream:38,
from /opt/local/include/gcc48/c++/iostream:39,
from ceva.cpp:1:
/opt/local/include/gcc48/c++/cwchar:44:19: fatal error: wchar.h: No such file or directory
#include <wchar.h>
If you need any information, tell me and I will provide it to you. Thank you for your patience!
[Added 2019 - Mojave/Catalina] XCode 10 has removed the placement of headers in /usr/include, even with the command line tools. If you want headers, and you're on you should be able to install a transitional package, which is available on Mojave. This package is not present on the Catalina. The headers are within the SDK for the appropriate release.
XCode 5/Mavericks have changed the defaults for where headers are located.
On prior versions of Mac OS X / XCode you would have found headers in /usr/include.
When you built gcc on the older release it picked up the headers from that location, and looks for them there now when you try to build code.
The problem is that the files are not there; they're somewhere under /Applications/Xcode.app/Contents/Developer.
You could futz about with a spec file to get it working consistently again, but the sanest thing to do is rebuild gcc.
As has been mentioned as well, you can install the command line tools using xcode-select --install, which will reinstall the developer tools, including the headers in /usr/include.
I tend to reinstall things like gcc when I upgrade my operating system as I encounter other errors due to changes in the environment. This is just a habit I've formed. It may not be the best habit, but it's saved me pain on numerous occasions.
[added 2017] As an addendum, if you install the command line tools, then the headers will be placed in /usr/include as well. The command to install the command line tools is xcode-select --install - this will allow you to use most compilers without having to specify the location of the headers manually.
This is how I got it working on Mac osx Mavericks:
Open terminal
type --> xcode-select --install
A pop-up windows will apear asking you about install tools
choose install tools
wait install to finish
Here is a manual method for updating XCode on OS X Mavericks:
Go into the developers site http://developer.apple.com
Then go to Downloads for Apple developers and there is a command line tools installer for Mavericks — here's the link (but you'll need a developers account for the link to work) http://developer.apple.com/downloads/index.action?q=xcode
I'm using MacOs Sierra 10.12.4, got the same problem.
I solved it by using:
/usr/bin/gcc
For me the fix was to uninstall old broken gcc:
brew uninstall gcc#5
I noticed paths like /usr/local/Cellar/gcc#5 in build output, while gcc#8 was also installed and is the one that was supposed to be used.

How can I compile and build a program using external library with command line tools come with Xcode?

I am coding a computer vision program, which is using OpenCV 2.4, by Xcode 4.4. I want to compile and make it in the Terminal by g++ or make command. But the system shows a lot of errors that the compiler cannot find the "opencv2/opencv.hpp" file and Vec3d, etc..!
My question is how to configure the system the I can make and build the code in Terminal? Thanks.
First, you need to have command line tools (I guess you already have it)
Bring up Preference in Xcode
Select "Downloads" tab
Select "Components' tab
Click 'install' on the command line tools line.
Then, you need to install OpenCV. I suggest to use Homebrew
setup homebrew, then
brew install opencv
It will install library in /usr/local, which is in g++'s standard lookup path, thus should be ok.
If you still need help, post the log file.

c++ cygwin and eclipse - binary not found error

I've spent hours looking up how to fix this problem but nothing has worked. I have eclipse Indigo with CDT and ive downloaded cygwin and packages such as g++, make file, etc. When I try to execute any code I end up with the error Launch failed. Binary not found. I've also set the system path C:\cygwin\bin. How can I set up eclipse so I can use it as my IDE for c++?
Found the problem, I didn't press the hammer button to build the project first. I've only used eclipse for java and I could just hit run and everything would work fine.
Try downloading MinGW, and using those compilers. The Cygwin tools require libraries that Eclipse may not load. The MinGW executables do not require any additional environment like Cygwin does.
Also, in order to use most Cygwin executables, you need to launch the Cygwin environment first.

Eclipse Ganymede and MinGW in Windows

I'm trying to get eclipse to work with MinGW.
I've done the following:
Downloaded CDT for eclipse.
Installed MinGW.
Added C:\MinGW\bin to my path.
Opening a command prompt (CMD) and typing g++ or alike works fine.
I run eclipse, create a "New C++ Project", and only get the option saying "other toolchains".
There's a MILLION tutorials out there saying eclipse should identify MinGW on its own. It doesn't, and I don't know what to do. I've tried reinstalling everying in just about every order posible. Still no luck.
I've also noted some tutorials say something about creating a "Managed C++ Project". I've no such option, all I get is "C++ Project" and "C Project"
edit:
I have eclipse ganymede, windows x86_64, version 3.4.2
http://download.eclipse.org/eclipse/downloads/drops/R-3.4.2-200902111700/index.php
Running the "Eclipse IDE for C/C++ developers" fails, since there's no x64 version for windows. The x86 version requires x86 JAVA installed as well, and installing two versions of java, gave nothing but trouble in the past.
The instructions for setting up MinGW in Ganymede are located here.
The following are instructions and
links on how to install the current
version of MinGW. Note that these
links may become inaccurate over time
as new versions of MinGW components
are introduced. Please check the MinGW
File Release section for the latest
versions.
Download and run the MinGW setup program, MinGW-5.1.3.exe.
Select download and install the MinGW base tools and the g++ compiler.
You may select the Current or
Candidate version of these tools. You
may also install any of the other
available compilers as well.
Do not install the MinGW Make feature as the MSYS version of make
from step 5 is a more complete
implementation of make.
The MinGW setup program currently does not install the gdb
debugger. To install the debugger,
download the file from the following
location: gdb-6.6.tar.bz2
Extract the contents of the file gdb-6.6.tar.bz2 to the same location
where you installed MinGW.
If you want to use Makefile projects, download and run the setup
program from the following location:
MSYS-1.0.10.exe. MSYS provides an
implementation of make and related
command line tools. This is not
required for other types of projects
with the MinGW toolchain, which use
CDT's internal build tools to perform
the build.
Following this process resolved any problems I had.
I had the same exact problem with Eclipse Galileo and CDT 6.0.1. It turns out that CDT only recognized MinGW when it's located under c:\mingw. I had it in c:\msys\mingw so that was the problem. After I changed that everything worked fine.
The distinction between managed make projects and makefile project was removed in CDT 4.x, I think. Now there is only one type of project, but you can select different builders. CDT includes an internal builder which does not use makefiles and another one which does.
First, save yourself the effort of "reinstalling in every order possible". That is also known as trial-and-error, and will only make you more frustrated. Apply the normal problem-solving skills you have as a programmer.
Given that you have MinGW installed, what happens if you download "Eclipse IDE for C/C++ developers", start eclipse.exe, and try to create a C++-project with a MinGW toolchain?
EDIT: remember: the key in getting help with problems like these is to produce a minimal example which fails. Also, it would help if you provided URLs to the packages you installed (MinGW, Eclipse, etc.).
EDIT: I just installed CDT using the Ganymede update site, downloaded and installed MinGW from here, and restarted Eclipse, and everything worked fine. I know that doesn't help you, but it does prove that the toolchain detection isn't completely broken. Something is weird on your side.
You could try Wascana Desktop Developer. Its a distribution of Eclipse CDT configured specifically for developing on Windows.
I had the same problem (i.e. Eclipse not finding MinGW on the PATH) after I removed some of the unused files/folders from MinGW. It was ~600 MB and I was tasked to trim it down before adding to source control. I got it down to a workable ~200 MB. When I tried to re-create an Eclipse workspace afterwards, MinGW disappeared from available toolchains. It reappeared after I put the original MinGW install on the path.
HTH