【发布时间】:2021-01-26 03:25:36
【问题描述】:
我在 c++ 中使用 std::ifstream 时遇到问题。我正在使用 Visual Studio 2019。每次我想初始化 std::ifstream 对象时,都会出现以下错误:
文件:Shader.obj
函数“void * __cdecl std::_Allocate_manually_vector_aligned(unsigned int)”中引用的 LNK2019 未解析的外部符号 __imp___invalid_parameter (??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPAXI@Z)
函数“void * __cdecl std::_Allocate_manually_vector_aligned(unsigned int)”(??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPAXI@Z) 中引用的 LNK2019 未解析的外部符号 __imp___CrtDbgReport
文件:msvcprtd.lib(locale0_implib.obj)
函数“public: static void __cdecl std::_Fac_node::operator delete(void *)”(??3_Fac_node@std@@SAXPAX@Z)中引用的LNK2019未解析的外部符号__imp___free_dbg
函数“public: static void * __cdecl std::_Fac_node::operator new(unsigned int)”(??2_Fac_node@std@@SAPAXI@Z)中引用的LNK2019未解析的外部符号__imp___malloc_dbg
Shader.h
#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include <GLFW/glfw3.h>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
class Shader
{
private:
/* some code */
public:
/* some code */
void setSourceFile(const std::string& filename);
}
Shader.cpp
#include "Shader.h"
/* some code */
void Shader::setSourceFile(const std::string& filename)
{
std::ifstream* shaderFile = new std::ifstream();
}
即使我只运行std::ifstream shaderFile();,甚至在将参数传递给构造函数之后,这些错误仍然存在。当我对此发表评论时,程序会正确构建。
【问题讨论】:
-
如果您只在
Shader.cpp中写入#include <fstream>会怎样? -
“即使我只运行
std::ifstream shaderFile();”,这些错误仍然存在 - 仅供参考,这甚至不是对象定义;它是一个名为shaderFile的函数的声明,它不接受任何参数并返回一个按值std::ifstream。 -
@StackDanny 没有任何改变。
-
这看起来像您正在将调试版本链接到非调试(发布)库。
-
调试和发布混用是不安全的。
标签: c++ visual-studio compiler-errors ifstream lnk2019