I was working a project in C++ and all of the sudden my Mac said that Xcode was finished updating, so I just exited out of the popup and didn't think anything of it. I went back to my project and tried to run my makefile and it said I need to be root to accept Xcode's terms. So, I just booted up Xcode, accepted the terms, and quit. Now, when I work on my project in Vim, I am getting all kinds of errors. E.g.
#include<iostream> // 'iostream' file not found
#include<string>
int main()
{
std::cout << "hello" << std::endl; // use of undeclared identifier 'std'
return 0;
}
I have no idea what has happened. Can anybody help me?
I use g++ to compile and this is the output of g++ --version:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx- include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
My Xcode version is now 6.0.1.
All this being said, I still seem to be able to compile my code. I am just getting all types of errors in Vim, related somehow to this Xcode update.
I use YouCompleteMe for error highlighting.
I believe I have found the solution. I am assuming that when Xcode updated, its folder structure changed.
I fixed this issue by changing my .ycm_extra_conf.py. I changed the flag line
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1'
to
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1',
Related
I just started using MinGW for Windows. When trying to create executable using
g++ a.cpp -o a.exe -std=c++14
for the code below:
#include <string>
using namespace std;
int main()
{
string x = to_string(123);
return 0;
}
I'm getting following error:
C:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../libmingwex.a(vsnprintf.o):(.text+0x0): multiple definition of vsnprintf
C:\Users\..\Local\Temp\cc4sJDvK.o:c:/mingw/include/stdio.h:426: first defined here
collect2.exe: error: ld returned 1 exit status
What is the root cause for this error and how can I make it go away? While I can easily find a replacement for to_string() function I'm not sure what is causing this error to occur in the first place.
Installing MinGW packages mingw32-libmingwex-* will link an appropriate version of vsnprintf and avoid the linker error.
This issue, i.e. multiple definition of vsnprintf, still exists in MinGW as December 2019.
After investigating a lot, I found the solution in the official mailing list.
It's a bug in mingwrt-5.2.2. Downgrading to the mingwrt-5.2.1 version solves that issue.
To do that, just input the following command:
mingw-get upgrade mingwrt=5.2.1
Then restart the MinGW shell.
Read the full story here.
Note: MinGW-w64 and MinGW are separate projects, so the accepted solution is not so helpful to me, as I want to keep MinGW and not to move to MinGW-w64.
I solved this issue using MinGW w64 compiler
download mingw-w64-install.exe
setup to Version: 6.3.0, Architecture: i686, Threads: posix, Exception: dwarf and Build revision: 2.
I hope this will be of some help.
There are multiple definitions of vsnprintf in both stdio.h and libmingwex.a. I am able to work this around by adding #define __USE_MINGW_ANSI_STDIO 0 to the start of the code, before any includes, which disables the definition of vsnprintf in stdio.h.
Disclaimer - I am completely new to C++ and the way this language works regarding compiling / linking. Using MacOS Mojave.
For a school course we are obliged to use the g++ compiler to compile our c++ projects. G++ seems to be successfully installed; g++ -v results in the following output:
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin17.5.0/8.1.0/lto-wrapper
Target: x86_64-apple-darwin17.5.0
Configured with: ../gcc-8.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc versie 8.1.0 (GCC)
I created my first "hello world" program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
When I tried to compile this code (using 'g++ file.cpp), the following terminal output prompted:
In file included from /usr/local/include/c++/8.1.0/bits/postypes.h:40,
from /usr/local/include/c++/8.1.0/iosfwd:40,
from /usr/local/include/c++/8.1.0/ios:38,
from /usr/local/include/c++/8.1.0/ostream:38,
from /usr/local/include/c++/8.1.0/iostream:39,
from ex1.cpp:1:
/usr/local/include/c++/8.1.0/cwchar:44:10: fatale fout: wchar.h: No such file or directory
#include <wchar.h>
^~~~~~~~~
compilation ended.
The whcar.h file is indeed not present in the above folder. After some digging, I found the whcar file in the following folder: /Library/Developer/CommandLineTools/usr/include/c++/v1
Unfortunately I am a bit lost and don't really know what I am talking about, consindering everything is really new for me.
It is greatly appreciated if anyone can guide me in the right direction.
Kind regards,
Thijmen.
For me, reinstalling Xcode Command Line Tools and g++ solved the same issue:
xcode-select --install
brew reinstall gcc
The last line is assuming you have installed homebrew.
I just found out the easiest way of this mess is just download the missing header file to your compiler folder. It will fix everything.
Earlier, I posed a related question.
I have the following program extracted from a large project in my Mac OS
#include <iostream>
int main(){
std::cout<<"hello"<<std::endl;
return 0;
}
Compiling it with Clang fails with the following error:
$ clang test.cpp
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^
1 error generated.
For information,
A) I have already installed xcode command line tools, using xcodeselect --install. But it seems iostream does not locate in the default search path of clang.
B) Using g++ instead of clang compiles the program. But in my problem, I am not allowed to use other compiler than clang, or to change the source program.
C) I can see workaround techniques, e.g, by tweaking the search path in .bashrc or with some symbolic link, etc. But I feel reluctant to use them, because it seems that I have an installation problem with my Clang and tweaking the path only helps to avoid one of these path issues.
clang and clang++ do different things. If you want to compile C++ code, you need to use clang++
Alternatively you can invoke c++ compiler directly by providing language name explicitely:
clang -x=c++
I am attempting to setup SDL2 for C++ with Eclipse on Windows 7.
In order to do so, I am following the tutorial in this link, which states that I must first install MinGW. So I follow the link provided in order to setup MinGW. I follow all the steps without issue. I then open Eclipse and attempt to build a simple hello world program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
To my surprise, this code doesn't build, with 6 errors.
I then proceed to simplify the program further:
int main()
{
return 0;
}
This also does not compile. There are two errors:
Program "g++" not found in PATH
Program "gcc" not found in PATH
Here is a screenshot.
However, my path does contain "C:\mingw\bin". I have also tried changing this to "C:\mingw". Looking inside "C:\mingw\bin", I find gcc and g++:
In addition, compiling a test program using the command line (g++ Test.cpp -o Test) works just fine, as does "g++ -v".
I have been searching the web for hours, and can't seem to find an answer as to why Eclipse can't seem to compile anything with MinGW. Questions I have looked at on SO (which haven't been able to fix my issue) include:
Eclipse mingw binary not found
Eclipse not finding c std libraries
g++ not found in path
Eclipse C++ : "Program g++ not found in PATH"
Program g++ not found in path
Program g++ not found in path C++ [duplicate]
Eclipse CDT (Juno) in Win7: Cannot find g++ in PATH, iostream unresolved and other fun stuff
Additional info:
Window > Preferences > C/C++ > Build > Settings > "CDT GCC Built-in Complier Settings MinGW [Shared]" : Toolchain MinGW GCC is not detected on this system.
I have also reinstalled Eclipse to no avail.
I realize that this may be a duplicate question of some that I have linked, but the information in previous questions have not been able to fix my problem, and I fear that adding a comment to an old question may not result in an answer.
Please request additional information as needed.
You need to set the environment for the c/c++ builder.
First you need to install the GNU tool-chain, you can choose either MinGW or Cygwin. You can see the steps here. I used MinGW.
Go to Window->Preferences->C/C++->Build->Environment and add a new variable, name it whatever you want for example a named it "MINGW", now paste the binaries directory of MinGW which is by default C:\MinGW\bin, you should have something like this:
Now when you create a new project you just have to select the MinGW tool-chain:
Hope that helps.
It appears as though I have fixed the problem for the moment.
In case others encounter the same issue:
Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Command changed from "g++" to "C:\mingw\bin\g++".
I am new to C++ and I am self-teaching. I am using code::blocks, and have a question. When I write hello world, nothing happens. This is what is says in the debugger window:
Building to ensure sources are up-to-date
Selecting target:
Debug
ERROR: You need to specify a debugger program in the debuggers's settings.
(For MinGW compilers, it's 'gdb.exe' (without the quotes))
(For MSVC compilers, it's 'cdb.exe' (without the quotes))
and here is the program:
#include <iostream>
using namespace std;
int main()
{
cout << "Helloworld!" << endl;
return 0;
}
also if you need it, here is the build log:
"hello world again - Debug": The compiler's setup (GNU GCC Compiler) is invalid, so Code::Blocks cannot find/run the compiler.
Probably the toolchain path within the compiler options is not setup correctly?!
Goto "Settings->Compiler and debugger...->Global compiler settings->GNU GCC Compiler->Toolchain executables" and fix the compiler's setup.
Skipping...
Nothing to be done (all items are up-to-date).
Try to download the debugger and the compiler again. It worked for me when I had this problem. Try downloading the 'gdb.exe' from the internet.