Visual Studio 2017 Error - language feature 'nested-namespace-definition' requires compiler flag '/std:c++17' - c++17

Using MS Visual studio I created a solution containing 2 projects called MainProject and CalcProject
MainProject is a console app that references CalcProject and only contains main() in a .cpp file
CalProject is a library and contains a few header files with the following:
Nml.h contains the following:
#include <cstdint>
#include " Ftr.h"
#include " Mtr.h"
namespace CalcProject::measure
{
class Mtr;
class Ftr;
class Nml
{
public:
...
Ftr.h contains the following:
#include <cstdint>
#include " Mtr.h"
#include " Nml.h"
namespace CalcProject::measure
{
class Mtr;
class Nml;
class Ftr
{
...
Mtr.h contains the following:
#include " Ftr.h"
#include " Nml.h"
namespace CalcProject::measure
{
class Ftr;
class Nml;
class Mtr
{
...
MainProject.cpp contains the following:
#include "pch.h"
#include "Ftr.h"
#include <iostream>
#include <string>
using namespace CalcProject::measure;
int main()
{
When I build the solution I receive the following error
Error C2429 language feature 'nested-namespace-definition' requires compiler flag '/std:c++17' MainProject
I tried to resolve this by specifying /std:c++17 in the C++ Language standard in the project properties but the error persists.
How can I fix this? Please advise on a possible solution. I am a beginner and this is my first C++ project using multiple header and cpp files to create a library.

Related

Using OMPL with Drake

I am trying to work with ompl on drake and am having issues with using the ompl headers in drake. I installed ompl using the default installation path and made the following changes in drake:
Added the following to the workspace:
new_local_repository(
name = "ompl",
path = "/usr/local/include/ompl-1.5/ompl",
build_file = "ompl.BUILD",
)
ompl.BUILD:
cc_library(
name = "ompl",
hdrs = glob(["**"]),
includes = ["include"],
visibility = ["//visibility:public"],
linkstatic = 1,
)
In my repository's BUILD.bazel:
drake_cc_binary(
name = "ompl_ex",
srcs = ["src/ompl_ex.cc"],
data = [],
test_rule_args = ["--target_realtime_rate=0.0"],
deps = [
"#gflags",
"#ompl//:ompl",
],
)
ompl_ex.cc
#include <memory>
#include <limits.h>
#include <unistd.h>
#include <fstream>
#include <string>
#include <gflags/gflags.h>
#include <iostream>
#include <ompl/config.h>
#include <vector>
namespace drake {
namespace ompl {
int DoMain(){
std::cout<<"the function is working"<<std::endl;
return 0;
}
} // namespace examples
} // namespace drake
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
return drake::ompl::DoMain();
}
The error I get:
infinite_horizon_ltl/src/ompl_ex.cc:10:10: fatal error: ompl/config.h: No such file or directory
#include <ompl/config.h>
I use spot libraries similarly and they seem to be working fine. Not sure what I am getting wrong in the case of OMPL. I checked on drakes git issues and found that there was an attempt at integration but the branch is deleted now, and the solution proposed does not seem to be working on my system.
I have found that it is easiest to work with drake as an external library in a cmake project. This works quite well with ompl. Here's a quick example which imports both drake and ompl as external libraries and solves a simple planning problem.
https://github.com/DexaiRobotics/drake-torch/tree/master/examples/drake-ompl
The output and video were made using the dexai2/drake-torch/cpu-nightly-ros docker which is available here: https://hub.docker.com/r/dexai2/drake-torch/tags
As an aside, depending on which version of Ubuntu you use, you may need change your gcc version - e.g. you need gcc-9 and g++-9 specified in the CMakeLists.txt for Ubuntu 20.04 and gcc-7 and g++-7 on 18.04. See notes here: https://drake.mit.edu/developers.html#id10

Is there an optimal way to use pre-compiled headers in multiple projects?

I have a solution with 2 projects, one is a static library and the other is an application that
links to it. In the static library I have a pre-compiled header file with the following code:
#pragma once
//C standard Library
#include <stdio.h>
//C++ Standard Library
#include <iostream>
#include <fstream>
#include <sstream>
#include <memory>
#include <functional>
//Data Structures
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
I have also added the necessary .cpp file and configured the project properties to use this specific pre-
compiled header. I also added the .h file to the top of every .cpp file as required. I proceeded to my
latter project and properly referenced the static library and wrote some simple code, here is an
example:
class Test : public Craft::Application
{
public:
Test()
{
}
~Test()
{
}
};
Craft::Application* Craft::CreateApplication()
{
return new Test;
}
This returned Test object will be linked with an entry point and proceeds through the pipeline and
encounters code from the std library, that's when I get these errors:
error C2039: 'string': is not a member of 'std'
message : see declaration of 'std'
error C3646: 'Title': unknown override specifier
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2039: 'string': is not a member of 'std'
message : see declaration of 'std'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error: missing ',' before '&'
error C2065: 'title': undeclared identifier
error C2065: 'width': undeclared identifier
error C2065: 'height': undeclared identifier
error C2614: 'Craft::Window::WindowProps': illegal member initialization: 'Title' is not a base or member
error C2039: 'unique_ptr': is not a member of 'std'
message : see declaration of 'std'
error C2143: syntax error: missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
I understand that this project doesn't recognize the header files in my pre-compiled header. I can
confirm that as I included these files in the application and this resolved all errors. This sparks many
questions though: This project links to the library, so why doesn't it recognize this pre-compiled
header? What's the best solution for this? Is it a pre-compiled header per project? Is it something
entirely else?
The solution is simply including your pch in every source file and adding any necessary headers used by the header file. The compiler will still use the pch but will also be able to define your functions in the header file.

Using Clang to get AST

I would like to use Clang to get to its AST to get some information about the variables and methods in a particular source file. However, I do not want to use the LibTooling facilities. I would like to, by hand, to write to code that would call the methods to parse the .cpp and then get the tree. I can not find any resources that tell me how to do this. Can anybody help?
If your goal is to learn how to drive Clang components to work with the compilation database, configure the compiler instance, and so on, then the Clang source code is a resource. Perhaps the source for the ClangTool::buildASTs() method would be a good place to start: see Tooling.cpp in the lib/Tooling/ directory of the source tree.
If your goal is to do an analysis that LibTooling doesn't support, and you just want to get the AST with minimal fuss, then either ClangTool::buildASTs or clang::tooling::buildASTFromCode might be of service. The ClangTool approach would be better if you need the compilation database to express compiler options, include paths, and so on. buildASTFromCode is fine if you have a standalone bit of code for lightweight tests. Here's an example of the ClangTool approach:
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/CommandLine.h"
#include <memory>
#include <vector>
static llvm::cl::OptionCategory MyOpts("Ignored");
int main(int argc, const char ** argv)
{
using namespace clang;
using namespace clang::tooling;
CommonOptionsParser opt_prs(argc, argv, MyOpts);
ClangTool tool(opt_prs.getCompilations(), opt_prs.getSourcePathList());
using ast_vec_t = std::vector<std::unique_ptr<ASTUnit>>;
ast_vec_t asts;
tool.buildASTs(asts);
// now you the AST for each translation unit
...
Here's an example of buildASTFromCode:
#include "clang/Frontend/ASTUnit.h"
#include "clang/Tooling/Tooling.h"
...
std::string code = "struct A{public: int i;}; void f(A & a}{}";
std::unique_ptr<clang::ASTUnit> ast(clang::tooling::buildASTFromCode(code));
// now you have the AST for the code snippet
clang::ASTContext * pctx = &(ast->getASTContext());
clang::TranslationUnitDecl * decl = pctx->getTranslationUnitDecl();
...

Error C1189 d3d10.h is included before d3d10_1.h

aI'm trying to make a Component based 3d engine and I'm getting this error over and over again, here it is:
error C1189: #error : d3d10.h is included before d3d10_1.h, and it will confuse tools that honor SAL annotations. If possibly targeting d3d10.1, include d3d10_1.h instead of d3d10.h, or ensure d3d10_1.h is included before d3d10.h c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d10_1.h 75
I suspect (but not sure) this came out when I created this h file:
#pragma once
#include <D3DX10math.h>
typedef D3DXVECTOR2 Vector2;
typedef D3DXVECTOR3 Vector3;
typedef D3DXVECTOR4 Vector4;
typedef D3DXMATRIX Mat4;
And my d3dclass include part:
#include <Windows.h>
#include <D3D11.h>
#include <D3DX11.h>
#include <DXGI.h>
#include <D3Dcommon.h>
I'm using the directx SDK june 2010
Please help
Thanks!

Getting compass blueprint and sass to work in ruby on rails

I have setup a new project and used compass to generate the blueprint style sheets. I now have the following code in my screen.scss
body.bp {
#include blueprint-typography(true);
#include blueprint-utilities;
#include blueprint-debug;
#include blueprint-interaction;
$font-color: #C6C6C6;
}
The font in my document does not change however. Using just color:#C6C6C6; works fine. What am I missing here
$font-color is a variable, not the color specification itself, so it should be something like this:
$font-color: #C6C6C6;
body.bp {
#include blueprint-typography(true);
#include blueprint-utilities;
#include blueprint-debug;
#include blueprint-interaction;
color: $font-color;
}

Resources