2

I have a problem with using std::ifstream in c++. I'm using Visual Studio 2019. Every time I want to initialize the std::ifstream object it gives me these errors:

file: 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)

file: 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();
}

These errors remains even if i run just std::ifstream shaderFile(); and even after passing arguments to the constructor. When I comment this, the program builds properly.

Theobaldus
  • 103
  • 7

1 Answers1

1

The problem was that I have linked some realease libraries(glew32.lib and glfw32.lib) mixed with debug libraries. So in Project Properties->Linker->General I have changed Additional Library Directories to the debug libraries and in Linker->Input changed the file names.

Thanks @drescherjm and @1201ProgramAlarm for advices!

Theobaldus
  • 103
  • 7
  • I am glad you have got your solution and thanks for your sharing, I would appreciate it if you mark them as answer and this will be beneficial to other community. – Barrnet Chou Oct 14 '20 at 01:38