我是一个非常新手的程序员,只是学习了一点 c,但我总是在 Linux 上用 gcc 和 Vim 做,但决定尝试使用 Visual Studio,我得到了 LNK2005 和 LNK1169 错误,我试过查找错误以及如何修复它们并正确使用 PCH,因为我认为即使我的程序太小而无法使用它,学习也会很有用。
据我了解,我需要#include "stdafx.h"
在我的源文件(称为' helloworld.c
')的顶部,我没有stdafx.c
从创建项目时的默认值中触及'',我创建了一个名为' bitwise.h
'的头文件,它有一个功能它叫' int bw()
'然后我有' stdafx.h
',我添加的只是#include "bitwise.h"
在我的标题中,我bitwise.h
试图包含#include "stdafx.h" #include "stdafx.c" #include <stdio.h>
甚至不包含任何内容。所有这些都破坏了我的程序。我可以编译它的唯一方法是如果我注释掉//bw();
然后我的程序编译就好了。
以下是我认为可能是罪魁祸首的文件:
你好世界.c
#include "stdafx.h"
int main()
{
printf("\tHello World!\n");
getchar();
bw(); //If this line is commented out everything works just Honky-Dory
getchar();
return 0;
}
按位.h
#include "stdafx.h" //I've tried lots of diffrent lines here, nothing works
int bw()
{
int a = 1;
int x;
for (x = 0; x < 7; x++)
{
printf("\nNumber is Shifted By %i Bits: %i", x, a << x);
}
getchar();
return 0;
}
标准数据文件
// stdafx.cpp : source file that includes just the standard includes
// $safeprojectname$.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
标准数据文件
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include "bitwise.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here