0

I know this might've been answered before but I've tried the answers and they don't work. I have a header file (test declaration.h) and a cpp file (definition of test.cpp) and finally a main cpp file (main.cpp). When I compile and run the project I get an error (C3861 'test': identifier not found). All of the files are in the same folder. I am using visual studio 2019. Why is this happening and what am I doing wrong?

EDIT

I have changed the files to not have spaces and now I get a linking error (LNK2019 unresolved external symbol "void __cdecl test(void)" (?test@@YAXXZ) referenced in function _main)

testdef.cpp

#include <iostream>
#include "test declaration.h"
using namespace std; 

void test()
{
    cout << "hi";
}

testdecl.h

#pragma once

void test();

main.cpp

#include <iostream>
#include "test declaration.h"

int main()
{
    test();
}
evilhoomans42
  • 75
  • 1
  • 7
  • You can better not use spaces in your file names. But how did you try to compile? – Maaike Jan 06 '20 at 22:31
  • You get a compilation error, not a linking error – UnholySheep Jan 06 '20 at 22:31
  • I am not sure that visual studio preprocessor supports space in the file name. Do you get error on include statement? You should always start to look on compile errors in order they come because it is quite possible later just result of the previous ones. – Slava Jan 06 '20 at 22:33
  • I changed the files and now I get a linking error. See edit on post – evilhoomans42 Jan 06 '20 at 22:36
  • 1
    The new linker error means you are not linking to `Test.obj` after compiling `Test.cpp` Did you actually add `Test.cpp` to your project makefile? – Remy Lebeau Jan 06 '20 at 22:37
  • Good now it became a duplicate – Slava Jan 06 '20 at 22:37
  • `test.cpp` probably is not part of your project. – drescherjm Jan 06 '20 at 22:38
  • Slava that post doesn't answer my question. I am not compiling and running the way you think I am. I compile in visual studio and run in visual studio by pressing ctrl + f5 – evilhoomans42 Jan 06 '20 at 22:42
  • If this is exactly what you have on sources, then your include paths are not correct (but maybe you forgot to change that here). Are you compiling for c or c++? Because it is c++ code (std::cout). – Maaike Jan 06 '20 at 22:45
  • ***pressing ctrl + f5*** It should be `ctrl+f7` to build. – drescherjm Jan 06 '20 at 22:51
  • Did you actually read the answers on duplicate? Because it covers MSVS as well. – Slava Jan 06 '20 at 22:53

0 Answers0