gpt4 book ai didi

c++ - LNK2019 : unresolved extrenal symbol when using std::ifstream

转载 作者:行者123 更新时间:2023-12-02 10:26:28 26 4
gpt4 key购买 nike

我在C++中使用std::ifstream时遇到问题。我正在使用Visual Studio 2019.每次我想初始化std::ifstream对象时,都会出现以下错误:
文件: Shader.obj

LNK2019 unresolved external symbol __imp___invalid_parameter referenced in function "void * __cdecl std::_Allocate_manually_vector_aligned(unsigned int)" (??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPAXI@Z)


LNK2019 unresolved external symbol __imp___CrtDbgReport referenced in function "void * __cdecl std::_Allocate_manually_vector_aligned(unsigned int)" (??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPAXI@Z)


文件: msvcprtd.lib(locale0_implib.obj)

LNK2019 unresolved external symbol __imp___free_dbg referenced in function "public: static void __cdecl std::_Fac_node::operator delete(void *)" (??3_Fac_node@std@@SAXPAX@Z)


LNK2019 unresolved external symbol __imp___malloc_dbg referenced in function "public: static void * __cdecl std::_Fac_node::operator new(unsigned int)" (??2_Fac_node@std@@SAPAXI@Z)


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();,甚至将参数传递给构造函数之后,这些错误仍然存​​在。当我对此进行评论时,程序将正确构建。

最佳答案

问题是我链接了一些与调试库混合的realease库(glew32.lib和glfw32.lib)。因此,在项目属性->链接器->常规中,我已将其他库目录更改为调试库,并在链接器->输入中更改了文件名。
感谢@drescherjm和@ 1201ProgramAlarm的建议!

关于c++ - LNK2019 : unresolved extrenal symbol when using std::ifstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64307280/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com