c++ compiling error with terminal - c++

I wrote a piece of code with xcode 7.2 on a mac which compiles and works fine. However when i try to compile from terminal with command g++ -std=c++11 -o main.cpp an error occurs undefined symbols for architecture x86_64
functionname(std::_1::basic_istream<char,std::_1::char_traits<char> >&)"
where functionname is a function I created that has a file stream as a parameter.I am new to these kinds of compiling errors, so help would be much appreciated.

Related

VS code c++ debugger setup using GDB does not work

So here's my problem. I have downloaded mingw g++ by using msys according to the official vs code website
Here are my files:
Now, when I try to build I get this error:
> Executing task: g++ -std=c++14 -g -o myfile.exe myfile.cpp <
cc1plus.exe: fatal error: myfile.cpp: No such file or directory
compilation terminated.
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command g++ -std=c++14 -g -o myfile.exe myfile.cpp" terminated with exit code: 1.
And if I do have a .exe file:
edit: I also started getting errors with
#include <iostream>
I would make this a comment if I could. What is the name of the file where you have written #include <iostream>?* I think if you change the name of that file to "myfile.cpp", you might stop getting that error. You will probably get a different error saying that "main() cannot be found" or something like that, but that's an improvement from your current spot.
*I see it's O3.cpp. Try changing that to myfile.cpp.

Trying to compile a C++ code with Root (Cern) parameters included

I working on trying to compile a code written in C++ and Root on my Mac. The code is from a colleague who works on a Linux laptop. In addition to the different OS's, I have both a different version of gcc and Root than her and I am not sure which difference is causing the code not to compile on my machine.
She has g++ 4.8 and root 5.(something). I have gcc 5.3.0 and root 6.06/02.
She has given to me the a line of code she uses to get her machine to compile the code
gcc -Wall -o executable_name code_name.cc `root-config --cflags --glibs`
But when I write on my machine, Terminal gives me the error
gcc: error: unrecognized command line option ‘-stdlib=libc++’
gcc: error: unrecognized command line option ‘-stdlib=libc++’
I need help generating the correct line to get gcc to compile the code.
The problem here is two-fold: You're on OSX and you are using GCC.
The problem with this is that root-config assumes that since you're on OSX you will be using the OSX-standard Clang compiler which have the -stdlib flag. Since you're not using Clang, but GCC (which doesn't have this flag) you get an error.
You have two possible solutions: Use clang++ instead of g++ to compile and build (requires you to install the compiler if it's not installed already, it comes with Xcode), or to modify the root-config script so it doesn't add -stdlib=libc++. There might be environment variables or flags that the root-config script checks that alter the behavior, but I don't know anything about the script, you have to check it for that.

Exec Format Error Eclipse CDT

I have a basic C++ program in Eclipse CDT:
#include <iostream>
using namespace std;
int main()
{
std::cout << "Hello World!";
}
However, when I try to build it, I get an Exec Format Error. Here is the output produced by the compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o hey.o "..\\hey.cpp"
g++: error: spawn: Exec format error
I am using MinGW Toolchain. I am on 64-bit Windows, and I think that may have something to do with it. Would anyone know how to get this program running?
Edit
Running the exact command in command prompt in the directory where my source file is works just fine, without throwing errors, but it still doesn't work in Eclipse
So, I have fixed this myself by installing the 64-bit version of MinGW (http://sourceforge.net/projects/mingw-w64/). It now compiles and builds noramlly

Libc++ linked programs fail with symbol lookup error

I've recently built libc++ from scratch as my prject needs some features that are not yet implemnted in libstdc++.
I try to compile the hello world program located in src/main.cpp with line
clang -Wall -stdlib=libc++ -std=c++11 -c src/main.cpp -obuild/main.o
and the build suceeds
Then I link it with
clang -lc++ build/main.o -o qasix
and the linking suceeds too.
But when I run the program with
./qasix
I get the following error:
./qasix: symbol lookup error: /usr/local/lib/libc++.so.1: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE
I would like to know why this is occurring and also how to fix it.
I am on Xubuntu 13.10 if that's of any help.
PS: This problem popped up yesterday. Earlier other libc++ programs would compile fine.
This started when I did a debug build of a program with the -g flag and it compiled and ran fine, but all later programs complained about this symbol lookup failure. Please help.
it appears that you need the support library "libc++abi". It provides things like low-level exception support, type_info support, etc.
For Ubuntu (as opposed to Xubuntu), it appears that you can get it here: http://www.ubuntuupdates.org/package/core/saucy/universe/base/libc++abi-dev

gcc -funit-at-a-time causing compile to fail

we have started linking our application with -libmysqlcppconn-static for MySQL support.
When we compile for debugging everything is ok, but when we compile for release using gcc -O2 we get errors.
We have tracked down the offending compiler option to be -funit-at-a-time.
We get may errors of the form:
libmysqlcppconn-static.a(mysql_connection.cpp.o): In function
sql::mysql::MySQL_Savepoint::getSavepointId()':
mysql_connection.cpp:(.text+0x8d): undefined reference to
std::allocator: :allocator()'
mysql_connection.cpp:(.text+0x133): undefined reference to
`std::allocator ::~allocator()'
We are working around this for now by including -fno-unit-at-a-time. Any insight into how we can correct this would be appreciated
it might be because you are using using gcc to compile the code.. try using g++ to compile the file
otherwise try using following command
gcc -lstdc++ file.cpp