in centos eclipse. Got a bug says "function runtime_error could not be resolved". I added -std=c++11 or -std=c++0x in the settings and rebuild the index. (see Multiple "could not be resolved" problems using Eclipse with minGW )
it still shows a bug in the CDT.
But in my makefile I added -std=c++0x it got compiled with no error.
the line has the bug is
throw runtime_error("error msg");
I included those header files
#include <cerrno>
#include <system_error>
using namespace std;
void main()
{
throw runtime_error("blabla");
}
Related
Here is a small c++ code, adapted from the tutorial Step 1 of CMake :
// tutorial.cxx
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello World" << std::endl;
return 0;
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
# set the project name
project(Tutorial)
# add the executable
add_executable(Tutorial tutorial.cxx)
I used the extension of vscode CmakeTools, and I noticed that every time I build the project, it recompiles everything, even if nothing was changed. After some investigations, I found that the configuration of the project is made by vscode using this command :
/usr/local/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/bin/clang-10 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-10 -H/home/user/Bureau/projet/step1 -B/home/user/Bureau/projet/step1/build -G "Unix Makefiles"
(and if I configure by hand in the terminal with this command, it has the same behavior).
I noticed that if I configure the build directory without the option -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-10, there is no problem afterwards: if a make if nothing has been charged in source, it doesn't recompile.
I have actually 2 questions :
Why does the option CMAKE_CXX_COMPILER:FILEPATH induces such a behavior?
How to configure vscode so it doesn't use this option anymore?
EDIT :
I tried to configure the project with another compiler (in the list, vscode proposes Clang10, GCC 8.4.0 and GCC 9.3.0). With Clang all is recompiled at each time, but this is not the case if I take GCC.
This answers my second question: use another compiler.
But still, I wonder why does Clang recompile everything ?
I have written a programm in C and GTK3. I am using Arch Linux and everything works fine. However, I have to use my program also on a rather old Ubuntu machine.
gtk+-3.0 3.10.8
GCC 4.8.4
With this setup the program does not compile
In the Header file of a custom GTK-Widget I have:
#ifndef __LAYER_ELEMENT_H__
#define __LAYER_ELEMENT_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE(LayerElement, layer_element, LAYER, ELEMENT, GtkListBoxRow)
/* Rest of file comes here */
When compiling it throws the error message:
expected ')' before GtkListBoxRow in the line with the G_DECLARE_FINAL_TYPE macro.
How can I fix this issue?
G_DECLARE_FINAL_TYPE was added to GLib in version 2.44 (see the documentation). If you want to compile on an old version of Ubuntu, you will either have to get hold of a backport of GLib 2.44 (or later) for that version of Ubuntu, and compile against that; or you will have to modify your code to not use any GLib APIs added after version 2.40.
I installed GCC (4.8.1) this morning and Eclipse Kepler (SR2). My Hello World compiled and ran fine, so I'm moving toward my goal of writing a C++ app using Boost. I installed Boost to "C:\Program Files\boost\boost_1_55_0" and added this path to Project>Properties>C/C++ General>Paths and Symols>[tab]Includes>GNU C++. However, when I compile, the path isn't showing up in the g++ command line, so understandably, the header file isn't getting found.
15:55:24 **** Incremental Build of configuration Debug for project BoostApp ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\BoostApp.o" "..\\src\\BoostApp.cpp"
..\src\BoostApp.cpp:1:32: fatal error: boost/filesystem.hpp: No such file or directory
#include "boost/filesystem.hpp"
^
compilation terminated.
15:55:24 Build Finished (took 78ms)
I realize this is a newb question and spent a few hours searching around and finding mostly direction to set the path, which I've done. I've checked the install and the header file is there. I've also done my own command line compile adding "-I C:\Program Files\boost\boost_1_55_0" to the command line and GCC found the header file fine.
Not sure where I'm going wrong. As mentioned, it's a new install of GCC, Eclipse, and Boost, so maybe I went wrong somewhere during the install or maybe creating the project? Or just a newb question? Below is the app I'm compiling which I copied from rosettacode.com
#include "boost/filesystem.hpp"
#include "boost/regex.hpp"
#include <iostream>
using namespace boost::filesystem;
int main()
{
path current_dir("."); //
boost::regex pattern("a.*"); // list all files starting with a
for (recursive_directory_iterator iter(current_dir), end;
iter != end;
++iter)
{
std::string name = iter->path().filename().string();
if (regex_match(name, pattern))
std::cout << iter->path() << "\n";
}
}
This might be a very dumb question...
I'm trying to use Boost.Python in an Xcode project (boost 1.50, xcode 4.4, OS X 10.8). I installed both boost and python through macports. I dragged the macports Python framework (/opt/local/Library/Frameworks/Python.framework) into the project and tried the most minimal program possible:
#include <boost/python.hpp>
int main(int argc, const char * argv[]) {
Py_Initialize();
Py_Finalize();
return 0;
}
and get:
/opt/local/include/boost/python/detail/wrap_python.hpp:50:11: fatal error: 'pyconfig.h' file not found
Do I need to explicitly add the framework header folder to the project's header search paths? That seems irregular... so hopefully I'm just misunderstanding something?
Just installed CDT for eclipse, with MinGW gcc. C program "HelloWorld" compiles and runs ok. But tried adding a class declaration in a new .h file to it. Syntax error on class definition. Tried writing my own class declaration and using the new class wiz.
Have used many other C++ ide's other than eclipse. Would like to use eclipse for team integration. What's the eclipse secret to get class declaration to work?
Here's the errors:
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o src\main.o ..\src\main.c
In file included from ../src/main.c:10:
../src/Logger.h:11: parse error before "Logger"
../src/Logger.h:11: syntax error before '{' token
Here's the class header file "Logger.h" where the error occurs.
#ifndef LOGGER_H_
#define LOGGER_H_
class Logger {
public:
Logger();
virtual ~Logger();
};
#endif /* LOGGER_H_ */
The project created in Eclipse was created as a C project, not a C++ project. Hence the absence of support for class declaration.
Solution: Created a new project using C++ type, moved the code to the new C++ project, deleted the old C project, renamed the new C++ project to the desired name, and ran clean & rebuild.
The indexer can get confused.
I did a Project->C/C++ Index->Rebuild and this cured the issue for me.