【发布时间】:2017-09-27 04:00:37
【问题描述】:
我是一个非常新手的程序员,只是学习了一点 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中我试图包含@987654329 @ 甚至不包括任何东西。所有这些都破坏了我的程序。我可以让它编译的唯一方法是,如果我注释掉//bw();,那么我的程序编译就好了。
以下是我认为可能是罪魁祸首的文件:
helloworld.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.c
// 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
// 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
【问题讨论】:
标签: c++ c visual-studio pch