Eclipse, Macos 10.8 and C++11 - eclipse

I'm trying to use C++11 but eclipse is having some trouble with it. I've used macports to get gcc48, and I've followed various guides for getting eclipse to use the new compiler, including this, this,
and I've also changed the compiler command from the eclipse standard to the g++-mp-4.8 as explained here
I am trying to build the following program:
#include <iostream>
#include<memory>
using namespace std;
int main() {
std::unique_ptr<double> ptr(new double);
*ptr = 11.345;
cout << (*ptr) << endl;
return 0;
}
The terminal will compile this fine,
make all
Building file: ../src/C++11.cpp
Invoking: Cross G++ Compiler
/opt/local/bin/g++ -I/opt/local/bin -I/opt/local/include -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"src/C++11.d" -MT"src/C++11.d" -o "src/C++11.o" "../src/C++11.cpp"
Finished building: ../src/C++11.cpp
Building target: C++11
Invoking: Cross G++ Linker
g++ -o "C++11" ./src/C++11.o
Finished building target: C++11
and the program runs just as expected. However, in eclipse, I still get the error message Symbol 'unique_ptr' could not be resolved.
I would like to continue using eclipse as more than just a project manager and makefile builder, so any help on this would be appreciated!

Rather than using g++, one can use clang++. I used the answers Error when compiling some simple c++ code, clang 3.1 can't see unique_ptr? and How to compile a C++0x code on Eclipse CDT on mac? as guides to come up with the following steps:
change the compiler in the Project->Properties->C/C++ Build -> Settings -> Gcc C++ Compiler -> Command (change g++ to clang++).
in Project->Properties->C/C++ Build -> Settings -> Gcc C++ Compiler -> Miscellaneous, append -std=c++11 -stdlib=libc++ to the flags.
do the same as one for the linker under C/C++ Build -> Settings -> Gcc C++ Linker -> Command
in Properties->C/C++ Build -> Settings -> Gcc C++ Linker -> Miscellaneous, add -stdlib=libc++ to the Linker flags.
in Properties->C/C++ General -> Preprocessor Include Paths, Macros,etc -> Providers -> CDT GCC Builtin Compiler Settings, turn off the Share option, and append -std=c++11 to the Command to get compiler specs.
The compilation works perfectly and the program runs well. That eclipse doesn't recognize the smart pointer appears to be a bug: see Turn off eclipse errors (that arent really errors)

Related

Using -fsanitizer on vscode

Using -fsanitizer while compiling programs helps in finding location of memory leaks easily. But how to use this with vscode.
I only know that for compiling a program in vscode through terminal we need to type in g++ file_name.cpp -o executable_name.exe and for running .\program_name
Adding -fsanitizer to this command as an argument does not work for me. How to compile your program using fsanitizer on vscode?
Edit: I have been trying to use it as
g++ -std=c++17 -O2 -Wall -fsanitize=address
tempCodeRunnerFile.cpp -o tempcodeRunnerfile.exe
But this keeps giving me some kind of error:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lasan: No such file or directory
collect2.exe: error: ld returned 1 exit status
This is unrelated to VSCode. The problem is your platform - MinGW traditionally has poor sanitizer support.
Your MSYS2 environment, MINGW64, only supports UBSAN (with stripped-down error reporting, compile with -fsanitize=undefined -fsanitize-undefined-trap-on-error).
There's also CLANG64 environment, which does have ASAN. Install its Clang (pacman -S mingw-w64-clang-x86_64-clang), and compile using clang++ located at C:\msys64\clang64\bin. If you're compiling from MSYS2 terminal, make sure you start the right one: launch it with clang64.exe, or the "MSYS2 Clang x64" shortcut (I don't remember the exact name).

swift-lldb compilation fails with c++11 error

I am trying to compile swift-lldb on Ubuntu 14.04 (following instructions from https://github.com/apple/swift-lldb). I have the following dependencies installed:
Clang-3.5
Cmake version 3.5.2
Python version 2.7.6
On running the build script step which is lldb/scripts/build-swift-cmake.py --test, I am seeing the following error:
CMake Warning at cmake/modules/HandleLLVMOptions.cmake:185 (message):
-fPIC is not supported.
Call Stack (most recent call first):
cmake/modules/HandleLLVMOptions.cmake:216 (add_flag_or_print_warning)
CMakeLists.txt:616 (include)
CMake Error at cmake/modules/HandleLLVMOptions.cmake:429 (message):
LLVM requires C++11 support but the '-std=c++11' flag isn't supported.
Call Stack (most recent call first):
CMakeLists.txt:616 (include)
I have defined environment variables CC and CXX to point to the clang C and C++ compilers.
root:/myswift# echo $CC
/usr/bin/clang
root:/myswift# echo $CXX
/usr/bin/clang++
I also found in the clang documentation that c++11 is supported by clang-3.5. Not sure what I am missing here. Can someone please help?
clang-4.0 mentioned as part of the installation should support the -std=c++11 flag (just tested clang-4.0.1). However, upgrading to clang-6.0 seems to solve this build process error.
Running cmake directly in the automatically created build directory (by the swift build scripts) could be used to investigate the build failure in more detail. To specify compilers here, rather than setting CC and CXX environment variables (which works well for GNU configure scripts), compilers can be set for cmake via
cmake -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ path_to_src_or_build_directory
An existing CMakeCache.txt might have to be removed, so that the above parameters are honored.
A problem with clang++ installations that I have observed is that clang++ cannot find C++ headers (i.e. if C++ headers are in non-standard locations other than /usr/include, unlikely in the case of Ubuntu though). In case /usr/bin/clang++ cannot compile a simple program like
#include <iostream>
using namespace std;
int main() {
cout << "hello" << endl;
return 0;
}
not being able to find the iostream include file, it might help to set --gcc-toolchain=/pathtoaworkinggcc, where pathtoaworkinggcc should include include, lib, bin, etc. of a working C++ compiler (possibly g++ in the case of a Ubuntu installation).

C++14 Syntax in Eclipse CDT compiles but marked as syntax error (indexer)

Eclipse CDT gives me a syntax error for a valid C++14 syntax.
Everything compiles and runs but the syntax highlighting is broken.
I have MinGW and Eclipse running. The C++14 program compiles and executes but I get incorrect syntax highlighting / syntax checking.
Here is my source code:
#include <iostream>
auto main() -> int
{
//Binary Literals C++14 with Digit separators C++14
auto seven = int{0b0000'0111};
std::cout << seven << std::endl;
std::cout << __cplusplus << std::endl;
return int{0};
}
And here is the output / build log.
You can see my compiler settings (-D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++14) and the highlighting in it.
What do I need to setup so syntax detecition allows for C++14 syntax?
EDIT: it seems like the Indexer is the right bet - I am unable to make the Indexer work as intended.
On Windows 7 I am using MinGW.
I open Providers and click on "CDT Built-In Compiler Settings MinGW" where I add -std=c++14. So the whole string is ${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}" -std=c++14 after I hit apply and ok I use Project->Index->rebuild in the hope of removing my errors. The Syntax error still persists.
This is essentially what is mentioned in the FAQ to get C++11 recognized by the indexer.
I have the latest MinGW Version installed. When I call g++ --version i get: g++ (GCC) 5.3.0 as a response. There is no manual for 5.3 but I would assume most of 5.4 is mostly valid for my version.
The problem seems to be that the support for C++14 is not added yet.
Here is a bugreport that collects all C++14 issues.
There is a depends on section where other bug reports alre listed. Among them the bug 451086 that specifically mentions Binary literals (N3472), Single-quotation-mark as digit separator (N3781).
So it seems like this issue is known and will be adressed at some point in the future.

Using clang++ for code analysis in an Autotools project in Eclipse

I am using Eclipse 4.2 on Mac OS 10.8, with the command line tools (Xcode 4.6.3) installed. The clang compiler supports C++11 by means of using the following flags: -std=c++11 -stdlib=libc++.
I have an Autotools-managed project in Eclipse. Real compilation works as expected after overriding CXX and CXXFLAFGS environment variables when configure is called. However, the static code analysis in Eclipse continues to use GCC (the version installed with Xcode is GCC 4.2), so there is no support for C++11, and lots of lines display errors that are not real ones, making static code analysis almost useless.
Using homebrew I also installed GCC 4.7, but I have not succeeded to make Eclipse use that version (or clang++) for performing static code analysis.
Is it possible, when using an Autotools-managed project, to make Eclipse use a different compiler for the static code analysis? Where should I specify that?
After installing Xcode 5, and following the directions in this question, I managed to solve the problem (I cannot test anymore whether this applies to Xcode 4.6 too).
The solution is to go to Project properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers -> CDT GCC Built-in Compiler Settings, and in Command to get compiler specs: append -std=c++11 -stdlib=libc++.
After doing that change, the line should look like:
${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11 -stdlib=libc++

Beaglebone C/C++ programing in windows 7

I have a Beaglebone (Rev: A6) and i want to develop C/C++ program in windows 7 using Eclipse and then transfer executable in the board. But i'm having trouble setting up compiler/debugger/toolchain needed for Beaglebone. Searching the internet only gives me how to setup environment in Linux like installing 'arm-linux-gnueabi', setting up the paths to 'includes' etc. I need a step by step instruction to set up the environment in Eclipse in a windows machine. Can anyone help ?
I have tried these steps:
1. I have GNUARM installed on windows.
2. On eclipse IDE i open a C++ project with Corss GCC.
3. From project -> properties -> C/C++ build -> settings i add 'arm-elf-' to every cross compiler command.
4. From the GNUARM installation directory i add few path to '.../include/' in the 'C++ General -> paths and symbos'.
my 'build all' shows something as below:
10:32:20 **** Build of configuration Debug for project h ****
make all
Building file: ../src/hello.cpp
Invoking: Cross G++ Compiler
arm-elf-g++ -I"C:\GNUARM\include\c++\4.1.1" -I"C:\GNUARM\include\c++\4.1.1\arm-elf" - I"C:\GNUARM\include\c++\4.1.1\backward" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP - MF"src/hello.d" -MT"src/hello.d" -o "src/hello.o" "../src/hello.cpp"
Finished building: ../src/hello.cpp
Building target: h
Invoking: Cross G++ Linker
arm-elf-g++ -L"C:\GNUARM\lib\gcc\arm-elf\4.1.1\include" -o "h" ./src/hello.o
Finished building target: h
10:32:23 Build Finished (took 2s.967ms)
It is simple 'Hello world' printing program. From the project explorer 'Debug->src->hello.o -[arm/le]' i copy it and when run on beaglebone with
chmod ugo+x hello.o
./hello.o
-sh: ./hello.o: cannot execute binary file
the above massage is printed. I don't know what i did wrong. Perhaps the ARM environment in eclipse is set up incorrectly.
Isn't hello.o the pre-linked object file (just the compiled content of hello.cpp)? It doesn't contain the startup code or any library functions. The linker adds those to produce the final output.
Don't you want to run the linker ouput file h (which should already be executable)?
i got my answer here. http://www.acmesystems.it/foxg20_eclipse_windows_c. CodeSourcery was the toolchain that i was looking for and this also explains how to setup the corss compiling environment.