View Full Version : Noob C question (Multiple markers at this line)
LoRd_MuldeR
4th January 2007, 22:02
I have to do a project in C, but never used it before.
Just doing some very basic stuff for testing.
I got two files so far:
hello.c
#include "wurst.c"
int main(void)
{
murks();
return 0;
}
wurst.c
#include <stdio.h>
void murks(void)
{
printf("Hallo Welt!\n");
}
Problem:
It gives this error message in wurst.c
Multiple markers at this line:
- first defined here
- multiple definition of '_murks'
Thanks for any advice :D
foxyshadis
4th January 2007, 22:41
Your project probably includes both files. If it's VC, you can have the file in the project list but need to make it excluded from the build. If it's just a makefile, remove the reference to wurst.c.
Of course, the general preferred method is a header file that both can reference, instead of referencing one source inside the other, so both files can be compiled separately.
LoRd_MuldeR
4th January 2007, 22:45
Your project probably includes both files. If it's VC, you can have the file in the project list but need to make it excluded from the build. If it's just a makefile, remove the reference to wurst.c.
Of course, the general preferred method is a header file that both can reference, instead of referencing one source inside the other, so both files can be compiled separately.
I use Eclipse + CDT + Cygwin/GCC
So I'll have to learn how to use header files I guess ;)
dancho
5th January 2007, 11:25
My advice to you is try CodeBlock IDE (http://www.codeblocks.org/), he support large number of compilers...
And for your problem , you dont have to compile wurst.c file too,just hello.c file...
LoRd_MuldeR
5th January 2007, 13:47
My advice to you is try CodeBlock IDE (http://www.codeblocks.org/), he support large number of compilers...
And for your problem , you dont have to compile wurst.c file too,just hello.c file...
Thanks, but for the moment I'm happy I got Eclipse/CDT to work :D
Nevertheless I certainly will give CodeBlock a try...
nfm
5th January 2007, 20:35
#include "wurst.c" line in hello.c is not needed, compiler knows about all .c files in current dir where main() is. You do not need to compile wurst.c, only hello.c because it's where main() is. I found codeblocks to the best IDE I could work with on Linux. In Windows I use VS2005 because it's great. Here's an excellent tutorial from howstuff works http://computer.howstuffworks.com/c.htm
LoRd_MuldeR
5th January 2007, 21:55
Okay, I got CodeBlocks plus MinGW running now.
That seems to work fine for what I need to do at the moment...
Manao
6th January 2007, 17:16
The proper way of doing what you want to do is not to include wurst.c in hello.c. You also need to define the prototype of murks() in hello.c as follow :void murks();
int main()
{
...
}
If you were to use murks() in several different files, the next step would be to create a header that contains the prototype, and to include that header in the c files that need the function.
LoRd_MuldeR
8th January 2007, 23:06
Okay thanks! I think I understood how to use header files now ;)
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.