LNK2019:使用std :: ifstream

问题描述

我在c ++中使用std::ifstream时遇到问题。我使用的是Visual Studio2019。每次我想初始化std::ifstream对象时,都会出现以下错误

文件 Shader.obj

函数“ void * __cdecl std :: __ Allocate_manually_vector_aligned(unsigned int)”(?? $ _ Allocate_manually_vector_aligned @ U_Default_allocate_traits @ std @@@ std @@ YApaxI>中引用的LNK2019不可解析的外部符号__imp___invalid_parameter

LNK2019无法解析的外部符号__imp___CrtDbgReport在函数“ void * __cdecl std :: __ Allocate_manually_vector_aligned(unsigned int)”中引用(?? $ _ Allocate_manually_vector_aligned @ U_Default_allocate_traits @ std @@@ std @@ YAPA

文件 msvcprtd.lib(locale0_implib.obj)

函数“ public:static void __cdecl std :: _ Fac_node :: operator delete(void *)”中引用的LNK2019不可解析的外部符号__imp ___ free_dbg(?? 3_Fac_node @ std @@ SAXpax @ Z)

函数“ public:static void * __cdecl std :: _ Fac_node :: operator new(unsigned int)”中引用的LNK2019不可解析的外部符号__imp___malloc_dbg”(?? 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 )。因此,在 Project Properties-> Linker-> General 中,我已将其他库目录更改为调试库,并在 Linker-> Input 中更改了文件名称。

感谢@drescherjm和@ 1201ProgramAlarm的建议!

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...