变量的类型不完整std :: String; string.h有很多错误

时间:2019-05-22 19:07:30

标签: c++ visual-studio stdstring

字符串非常错误。我已经使用它们好几个星期了,但是直到星期一中旬,我开始遇到奇怪的问题: [Clang IntelliSense] Error: variable has incomplete type 'std::string' 每当我尝试做一个字符串。当我尝试wstringostringstream而不是stringstream时,会发生类似的错误。 initializing std::string* s也可以,但s->append(...)的结果是"member has access into incomplete type 'std::string'"

所有这些都是因为Visual Studio(VS)突然找不到我已经使用了几周的某些#includes,包括一些标准库(不记得是因为...)。我通过让VS搜索正确的文件并找到了一些文件(不确定它们是否与以前相同或不同)来解决该问题,因此它与#include语句不再有问题,但是现在我遇到了这个问题。

我已经使用<string.h>罚款了数周。在研究此问题时,我读到<string.h>是使用错误的文件,因此我尝试了#include <string>,但没有区别。此后,我尝试了<strings.h><cstring>,但两者之间也没有区别。

我检查了我的外部依赖项,string.h有很多错误,我认为这很奇怪,因为它是我没有碰过的标准文件。

我正在使用VS2015,GNU make,并且我看到了Clang IntelliSense,但在这里我也看到了一些g ++,所以我不确定它实际上在使用什么编译器。也使用visualGDB 5.3。让我知道我是否忘记了什么。

#include <iostream>
#include <string>
#include <sstream>
int main(int argc, char *argv[])
{
std::string message = "uncomment";
...
message

是突出显示为有问题的部分(类型不完整)

std::wstring wideMessage;

也是不完整的类型

预期结果:过去几周没有问题。我能够声明,初始化,append()等等 实际结果:无法编译/调试 错误:variable has incomplete type 'std::string' variable has incomplete type 'std::wstring' no matching constructor for initialization of 'std::ostringstream'

我在这里看到许多类似的问题,但是所有问题都与前向声明有关,我不认为这与这有什么关系。我对类,结构或函数没有任何疑问;甚至在main()中声明变量都是有问题的

编辑:基于this answer,很可能使用VC ++ 14.0作为编译器,但我不知道如何确定

编辑2:错误消息:

1>  VisualGDB: Sending 45 updated source files to build machine...
1>  VisualGDB: Run "make  CONFIG=Debug" in directory "/tmp/VisualGDB/c/Users/pthien/VS/Whatever/Whatever" on pthien@buildserver (SSH)
1>  /opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -ggdb -ffunction-sections -O0 -std=c++11 -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -ggdb -ffunction-sections -O0 -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include -I/opt/googletest-master/googletest/include -I/opt/boost_1_61_0 -I../../cereal/cereal-1.2.2/cereal-1.2.2/include -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/websocketpp-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/websocketpp -I/opt/curl-7.54.0 -I/opt/boost_1_61_0/boost -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/easywsclient-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/uWebSockets-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2/experimental -I/opt/boost_1_61_0/boost/tr1/tr1 -I/opt/boost_1_61_0/tools/build/src/engine -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2 -I/opt/curl-7.54.0/include -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/cereal -I/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/include-fixed -I/opt/boost_1_61_0/boost/compatibility/cpp_c_headers -I"../../../../../Program -IFiles -I(x86)/Microsoft -IVisual -IStudio -I10.0/VC/crt/src" -I"../../../../../Program -IFiles -I(x86)/Microsoft -IVisual -IStudio -I14.0/VC/include" -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2/arm-poky-linux-gnueabi -DDEBUG  -c Whatever.cpp -o Debug/Whatever.o -MD -MF Debug/Whatever.dep
1>  C:\Users\pthien\AppData\Local\VisualGDB\RemoteSourceCache\buildserver\0008\include\wchar.h(459,20): note :    'wcstold'
1>   extern long double wcstold (const wchar_t *__restrict __nptr,
1>                      ^
1>  Whatever.cpp: In function 'int main(int, char**)':
1>C:\Users\pthien\VS\Whatever\Whatever\Whatever.cpp(138,47): error : 'strlen' was not declared in this scope
1>     size_t request_len = strlen(webSocketRequest);
1>                                                 ^
1>  Makefile:160: recipe for target 'Debug/Whatever.o' failed
1>  make: *** [Debug/Whatever.o] Error 1
1>  -------------------------------------------------------------
1>  Command exited with code 2
1>  Executable: make
1>  Arguments:  CONFIG=Debug
1>  Directory: /tmp/VisualGDB/c/Users/pthien/VS/Whatever/Whatever
1>VisualGDB : error : Command-line action failed
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3073: The command ""C:\Program Files (x86)\Sysprogs\VisualGDB\\VisualGDB.exe" /build "C:\Users\pthien\VS\Whatever\Whatever\Whatever.vcxproj" "/solution:C:\Users\pthien\VS\Whatever\Whatever.sln"  "/config:Debug" "/platform:Win32"" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

这大约是输出的10%,包括开始和结束。奇怪的是strlen()的问题。它在IDE中没有强调,所以我不知道它有问题。这是有道理的,因为我将#include<string.h>的{​​{1}}注释掉,而strlen()在其中之一中。

2 个答案:

答案 0 :(得分:0)

如果完全从已有的代码中复制代码,则在argc的定义中会看到两个main的声明。您的编译器肯定会抛出错误。也许您的编译器会延迟读取错误,直到您在std::string中声明main为止? (我有一个编译器在实际错误之后几行似乎没有关联的地方抛出了一个错误。)因此,您可能已解决了错误的文件路径问题,但是您对main的错误定义可能会抛出错误编译器关闭。

现在,如果那不起作用,您提到看到使用了许多编译器。如果看到某个特定的编译器抛出该错误,则可能需要单独更新所述编译器。编译器的功能是模块化的,因此您可以选择用于哪个编译步骤的编译器。 VS可能正在这样做以获得最佳结果。有时,编译器会随身携带要使用的文件,因此更新(甚至取消/重新安装)编译器应修复随身携带的文件。 (Windows愿意为您做所有事情,因此,如果尝试分别更新部件,您实际上可能会搞砸。无论如何,这始终是我的经验。但是,我已经有一年没有使用Windows了,所以可能已经改变了。)

如果仍然不能解决问题,则可能必须卸载/重新安装VS。我承认对VS一无所知,因为我使用Emacs进行编辑,并使用Makefile / g ++进行编译。但是我的猜测是,VS可能会随身携带所需的所有编译器和文件,因此更新或取消/重新安装将(有望)解决您的问题。

答案 1 :(得分:0)

设法通过避免从我的目录列表中删除未使用的库,然后reloading all directories来避免此问题,但可能无法解决仍然未知的潜在问题。我不相信任何问题可以解决,因为重新加载目录会产生随机结果。有时它可以解决问题,有时又会导致新问题。就在昨天,我重新加载,然后找不到system.h和time.h(不记得名字了)。我正在对此进行故障排除,但问题在几个小时后消失了。无论如何 我发布了一个后续问题here