I'm a pretty novice programmer, just learning a little bit of c, but I always did it on Linux with gcc and Vim but decided to try using visual studio and I'm getting LNK2005 and LNK1169 errors, I've tried looking up the errors and how to fix them and properly use PCH because I think it would be useful to learn even if my programs are too small to make use of it.
From my understanding I need to #include "stdafx.h"
at the top of my source file (called 'helloworld.c
') I haven't touched 'stdafx.c
' from the default that came when I create the project, I created a header file called 'bitwise.h
' and it has one function in it called 'int bw()
' I then have 'stdafx.h
' and all I added was #include "bitwise.h"
In my headerbitwise.h
ive tried to include #include "stdafx.h" #include "stdafx.c" #include <stdio.h>
and even not including anything. all of these break my program. The only way I can get it to compile is if i comment out//bw();
then my program compiles just fine.
here are the files that I think may be the culprit:
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;
}
bitwise.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