I'm writing a project in Vulkan and it compiles and runs fine. The code is the same as it always was, but after some software updates (Steam, Visual Studio, etc.) an error has been popping up.
I mention steam as that was causing a separate runtime error. The same error as here: https://www.reddit.com/r/vulkan/comments/8ybq6f/need_some_help_debugging/e29qptx/
Anyway, the line:
const std::vector<const char*> validationLayers = { "VK_LAYER_LUNARG_standard_validation" };
and ones like that using std::vector and std::array give me the error: Ambiguous symbol 'const std::vector<const char*>'
My includes and defines are as follows:
#define GLFW_INCLUDE_VULKAN
#define GLM_FORCE_RADIANS
#define STB_IMAGE_IMPLEMENTATION
#include <glfw3.h>
#include <glm.hpp>
#include <gtc/matrix_transform.hpp>
#include <stb/stb_image.h>
#include <iostream>
#include <stdexcept>
#include <functional>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <array>
#include <chrono>
#ifdef NDEBUG
const bool enableValidationLayers = false;
#else
const bool enableValidationLayers = true;
#endif
So if there's a way to suppress this particular error highlighting, or if there is a genuine conflict, I'd love to know where it is / how to do it.
Like I say, it still runs fine, but it is annoying to look at my scroll bar and see a bunch of red markers that would normally indicate my program not compiling.
This turned out to be an issue with the version of ReSharper I was using. It is also reported here: https://resharper-support.jetbrains.com/hc/en-us/community/posts/360000430159-Intellisense-issue-with-C-17-standard?flash_digest=bbcceaf4d5a9c12c634a59aba32fc2143a325734
The solution is to turn it off or upgrade to R++ 2018.2
Related
I have a problem with the inclusion of header "queue" via a precompiled header file in c++ (VS 2019).
My Visual Studio solution consists of two projects, one engine project (static library) and one sandbox project (links the engine project) to test the engine's functionality. The engine project uses a precompiled header file, in which i just included "queue" since i am implementing a message system. Both projects are using C++17.
Visual Studio compiles the engine project without a problem, the sandbox project then throws the following error while compiling:
Error C2039 'queue': is not a member of 'std' (path\to\engine\message_handler.h)
As soon as I include "queue" directly in message_handler.h (see code excerpt), the error vanishes and the project starts up just fine.
I have been using the precompiled header for almost a year now and never had any problems.
Can anyone help me with this?
Following are the relevant excerpts from my code.
Precompiled header:
#pragma once
//memory
#include <memory>
//timing
#include <chrono>
#include <ctime>
//container
#include <vector>
#include <queue>
#include <unordered_map>
#include <array>
//string and streams
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
//misc
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <random>
message.h
struct Message
{
Message(){}
uint32_t id_;
};
message_handler.h
#pragma once
//#include <queue> //fixes the issue
#include "message.h"
using UnqPtr = std::unique_ptr<Message>;
class MessageHandler
{
public:
MessageHandler();
private:
static constexpr uint32_t maxMessages_ = 10000;
std::queue<UnqPtr<Message>, std::vector<UnqPtr<Message>>> msqQueue_;
};
message_handler.cpp
#include "trpch.h" //precompiled header
#include "message_handler.h"
MessageHandler::MessageHandler()
{
//reserve space in the underlying vector
std::vector<UnqPtr<Message>> queue;
queue.reserve(maxMessages_);
msqQueue_ = std::queue{queue};
}
My problem is pretty much what the title says:
When I use STRG-ALT-F to format my C++ files VSC also messes with the order of #includes.
And of cause this leads to errors that were not there before… :-(
For example this
#include "soc/soc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "XClk.h"
#include "DMABuffer.h"
becomes this
#include "DMABuffer.h"
#include "XClk.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "soc/soc.h"
… and subsequently fails compile.
Is there a way to forbid the formatter reordering and stick to formatting stuff?
Using PlatformIO in VSC on OSX.
I am trying to compile C++ code shown below but I got an error saying,
In file included from src/LM.h:3:0,
from src/LM.cpp:1:
src/common.h:30:13: error: ‘hash’ is already declared in this scope
using tr1::hash;
This is the command I used to compile the files below.
g++ -std=c++11 -Wall src/Foo.cpp
Foo.cpp
#include "Foo.h"
...
Foo.h
#ifndef FOO_H
#define FOO_H
#include "common.h"
//more code here
#endif
common.h
#ifndef _COMMON_H_
#define _COMMON_H_
#include <iostream>
#include <fstream>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <array>
#include <algorithm>
#include <set>
#include <tr1/unordered_map>
#include <tr1/functional>
namespace std {
using tr1::unordered_map;
using tr1::hash;
} // namespace std
using namespace std;
//more code here
#endif
I want the source code to use std::tr1::unordered_map and std::tr1::hash rather than std::unordered_map and std::hash(Actually I am making some modifications to distributed files which does uses std::tr1::unordered_map and std::tr1::hash).
What is possibly wrong with my codes?
UPD:
https://github.com/clab/fast_align/blob/master/src/port.h seems to do the same thing as mine. However, this compiles without any problem... Have any idea?
There is already std::hash in C++11. You cannot redefine it. You can use another name for tr1::hash.
Probably the best idea (if you really want to use std::tr1::hash/std::tr1::unordered_map instead of C++11 structures) is to write your own namespace in which using all structures, that you want without std::hash/std::unordered_map.
namespace common
{
using std::tr1::hash;
using std::tr1::unordered_map;
using std::vector;
// and so on
}
I am migrating a huge project from Qt 4.x to 5, (in fact I have asked for help several times here, I couldnt be more grateful for your help).
I am getting the next error:
..\marssies\userlayerswidget.cpp: In member function 'void
LayersModel::importFromOld()':
..\marssies\userlayerswidget.cpp:1736:60: error: 'SHGFP_TYPE_CURRENT'
was not declared in this scope
It doesnt make too much sense, as I have the correct header included, here are all the includes:
#include "userlayerswidget.h"
#include "appcommon.h"
#include "messagebox.h"
#include "polyline.h"
#include "painterbar.h"
#include "rectangle.h"
#include "polygon.h"
#include "label.h"
#include "line.h"
#include "point.h"
#include "encsymbol.h"
#include "touchswibz.h"
#include "mapmodulelist.h"
#include "offlinelayersaver.h"
#include "circle.h"
#include <QMenu>
#include <QDir>
#include <QDesktopServices>
#include <QtDebug>
#ifdef _WIN32
#include <Shlobj.h>
#endif
And here is the piece of code that makes use of SHGFP_TYPE_CURRENT:
void LayersModel::importFromOld() {
TCHAR appPath[MAX_PATH];
if (!(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appPath))) {
//code
}
I have researched and everything is correct according to http://msdn.microsoft.com/en-us/library/bb762181%28VS.85%29.aspx
I tried to find other people with the same problem but either the context was different or the question wasnt answered.
Thankyou.
In ShlObj.h is SHFGP_TYPE_CURRENT defined like this:
#if (_WIN32_IE >= 0x0500)
typedef enum {
SHGFP_TYPE_CURRENT = 0,
SHGFP_TYPE_DEFAULT = 1,
} SHGFP_TYPE;
#endif
So one can do this:
#define _WIN32_IE 0x0500
#include <ShlObj.h>
Or another way is to directly use value 0 or 1 as parameter to SHGetFolderPath.
Doing more research I found an answer that was to replace SHGFP_TYPE_CURRENT with a literal 0, I did it and it compiled, but I'm not sure if it will be the same (I haven't written this program, I'm just migrating it). So if anybody could give some insight it would be nice.
Source: http://webcache.googleusercontent.com/search?q=cache:http://www.dreamincode.net/forums/topic/200660-undeclared-variable/
During linking code on ubuntu I get following error
undefined reference to 'std::__default_alloc_template<true, 0>::deallocate(void*, unsigned int)'
I tried several g++ compilers but nothing changes. The reason I found in previous answers is wrong configuration if includes. Here are includes in the code:
#pragma warning(disable:4786)
#include <stdio.h>
#include <map>
#include <string>
#include <vector>
#include <png.h>
#include <math.h>
#include <ft2build.h>
#include <gd.h>
#include FT_FREETYPE_H
using namespace std;
#ifndef WIN32
#define stricmp strcasecmp
#else
#include <io.h>
#include <fcntl.h>
#endif
Please help to fix those includes?
Your are probably compiling and linking with gcc instead of g++. For compilation, there's not much difference. GCC uses the file extension to guess the real language, but when linking, g++also pulls in the C++ Standard library, which is where allocators are usually defined.