MingW environment paths - c++

I am trying to compile a simple program but the MingW C++ compiler cannot find the path. I have two files one is C:\main.cpp the other one is C:\Include\test.h
#include <iostream>
#include "test.h"
using namespace std;
int main()
{
cout << "test" << endl;
getchar();
return 0;
}
I have modified the CPATH, CPLUS_INCLUDE_PATH enviroment vars to include the C:\Include path but it still will not compile with g++ c:\main.cpp -o c:\main.exe
Output from command line.
c:\main.cpp:2:18: fatal error: test.h: No such file or directory
compilation terminated.
Also I used this registry file. Still doesn't work.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\Include"
"C_INCLUDE_PATH"="C:\\Include"
"CPLUS_INCLUDE_PATH"="C:\\Include"

There's not really enough information here, and storing source files in the root is suspect, but you might try:
g++ -I Include c:\main.cpp -o c:\main.exe
Assuming your cwd is C:\

This plus system restart was needed.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"LIBRARY_PATH"="C:\\Include"
"C_INCLUDE_PATH"="C:\\Include"
"CPLUS_INCLUDE_PATH"="C:\\Include"

Related

/usr/bin/locale: source file is not valid UTF-8

using g++ to compile cpp file in macOS.
macOS v10.15.4
Apple clang version 11.0.3 (clang-1103.0.32.62)
hello.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "hello word" << endl;
return 0;
}
in terminal I run:
g++ hello.cpp
CPLUS_INCLUDE_PATH environment variable has an incorrect value.
Simple fix:
export CPLUS_INCLUDE_PATH=":/usr/local/include"
Similar problem happened for me on Catalina10.15.7 + gcc10.2 (homebrew), and CPLUS_INCLUDE_PATH method from Lin Weiye didn't work somehow.
Manually changing line 140 of ostream header from
include <locale>
to
include "locale"
did work. This will stop ostream from looking for locale executable via PATH, and force to look locale header in the same directory where ofstream header is.

Xcode 11.1: iostream' file not found

I just updated my MacBook Pro to macOS Catalina 10.15, and tried to compile and run a C++ command line program, but I had a problem which didn’t exist on previous versions;
This is simply the code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!\n";
return 0;
}
The code compiles and outputs the expected, but still the Xcode says:
fatal error: 'iostream' file not found
I tried changing the Build Settings/C++ Standard Library to libstdc++, but a warning says:
warning: include path for stdlibc++ headers not found; pass '-stdlib=libc++' on the command line to use the libc++ standard library instead
And the same iostream error still exists.
I'm compiling from the command line, and none of the answers listed here (or elsewhere) worked for me.
What does seem to work (so far) is to add the following to .profile or whatever script your terminal uses to start up: (zsh, csh, bash, etc.)
export C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include
export CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include
You will probably have to change MacOSX10.15.sdk whenever you upgrade your operating system.
C_INCLUDE_PATH and CPLUS_INCLUDE_PATH are options for the clang toolchain rather than MacOS environment, so hopefully this solution will work long-term, unlike xcode-select --install (which won't fix the include directories on an upgrade) or ln -s ... /usr/include (which is now forbidden by System Integrity Protection).
I had the same problem and used the following youtube video to fix it.
https://www.youtube.com/watch?v=hrPm7tWC-BI&feature=youtu.be
or you can follow this path. Make sure to include the quotation marks
Project - Build Settings - Search Paths - Headers Search Paths, and add the following path:
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/"
So, I restarted my laptop and everything seems to be fine right now, thanks for those who tried to help.
libstdc++ is not OK for Xcode Build & Compile time,
libstdc++ is OK for iPhone Run Time
From answer recommended by #Alan Birtles
libstdc++ Support was removed from the iOS 12.0 Simulator runtime, but
it remains in the iOS 12.0 (device) runtime for binary compatibility
with shipping apps.
I encountered this when declaration in .hpp file.
#include <iostream>
#include <string>
OK with
#ifdef __cplusplus
#include <iostream>
#include <string>
// usage code
#endif
I tried a fresh Catalina install with Xcode. I copied and pasted your code into "test.cpp" and then ran:
clang++ test.cpp
in the same directory as the "test.cpp" file from Terminal. The result was an "a.out" file which when run:
./a.out
output the required "Hello, World!" result. Hopefully that is of some use (as a point of reference).

Linker error when linking C++ code with USB driver (ftdi)

I am on a Mac OSX and I am trying to start using the C ftdi drivers I installed using brew
brew install libftdi
That installed the library in the directory /usr/local/Cellar/libftdi/1.2 And I have the following C++ code
#include <iostream>
#include <ftdi.h>
using namespace std;
int main() {
struct ftdi_context ftdi;
ftdi_init(&ftdi);
cout << "Hello World" << endl;
return 0;
}
How should I compile this to make it work? I am including the include/ directory so the compiler can find the header file but I do not know which object file should be linked. I am trying to using the following command
g++ -I /usr/local/Cellar/libftdi/1.2/include/libftdi1/ /usr/local/Cellar/libftdi/1.2/lib/libftdi1.a test.cpp
But I am getting bad linker errors even though I have included the .a file. The lib/ directory has the following contents
cmake
libftdi1.2.2.0.dylib
libftdi1.2.dylib -> libftdi1.2.2.0.dylib
libftdi1.a
libftdi1.dylib -> libftdi1.2.dylib
pkgconfig
Is there something else I should try and link it to? Even if you are not aware of this particular driver is there something in general that I should be doing for drivers like this that I have not done?
Thanks for the help!

Trouble compiling Tensorflow in c++/Eclipse

I have trouble getting Tensorflow to work in my c++ environment: Eclipse.
I git cloned tensorflow, built with bazel, and installed the resulting pip-package exactly like described here:
https://www.tensorflow.org/versions/r0.7/get_started/os_setup.html#installing-from-sources
I created a new c++ project in Eclipse and added the /home/tensorflow to the include paths. However, when I try to build a simple "hello world" project with a few includes from TF I run into this error:
23:05:39 **** Incremental Build of configuration Debug for project cat_face ****
Info: Internal Builder is used for build
g++ -I/home/name/tensorflow -O0 -g3 -Wall -c -fmessage-length=0 -o src/cat_face.o ../src/cat_face.cpp
In file included from ../src/cat_face.cpp:2:0:
/home/name/tensorflow/tensorflow/core/public/session.h:22:48: fatal error: tensorflow/core/framework/graph.pb.h: No such file or directory
#include "tensorflow/core/framework/graph.pb.h"
^
compilation terminated.
23:05:39 Build Finished (took 186ms)
It seems to look for a file, which doesn't exist in the Tensorflow directory. Why is it looking for something that doesn't exist? I checked it out and the file really isn't there, even though I followed all steps.
My program was very simple:
#include <iostream>
#include "/tensorflow/core/public/session.h"
#include "/tensorflow/core/platform/env.h"
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
}
Where could this have gone wrong?
I think you are supposed to use bazel instead of cmake and make to build you project.
From what I know graph.pb.h is created by bazel during the build process.
Someone else had a similar problem: https://github.com/tensorflow/tensorflow/issues/1890

Include paths not found while compiling with g++ on MacOS

I'm trying to compile the simplest program on MacOS 10.6 like:
$ g++ -o hello hello.cpp
the following source:
#include <iostream>
int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
return 0;
}
I'm getting the error:
hello.cpp:1:20: error: iostream: No such file or directory
hello.cpp: In function ‘int main(int, char* const*)’:
hello.cpp:4: error: ‘cout’ is not a member of ‘std’
So obviously I have to add the include path somewhere. My question is where can I find the include directories and how can add them globally (I don't want to provide the include path whenever I want to compile).
I just installed the XCode 3.1.4 and managed to compile it via Xcode, but not via command line. I found some header files in this directory:
/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers
and tried to add it to the HEADER_SEARCH_PATHS after reading this question, but no luck.
I'm developing on Linux and everything is working fine there, but I want to continue doing that on MacOS. Any help?
On my Mac, that include file is in /usr/include/c++/4.0.0/iostream . Are you sure
you have all the command-line development tools installed? They might not be by default;
I'm pretty sure I had to install it manually when I first set up my Mac. There should be a "developer tools" package somewhere on your OS X installation media.
Or, if you want to make sure you're getting the latest version, you can download it from:
http://developer.apple.com/technology/xcode.html
$ g++ -o example.bin example.cpp //to compile
$ ./example.bin //to run
It's code:
#include <iostream>
using namespace std;
int main () {
cout << "Hello, World!\n";
return 0;
}