![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Unverified User
Join Date: Jun 2005
Location: NJ
Posts: 23
Rep Power: 0
![]() |
hey folks,i havent been doing that much programming over the last few months but ive gotten back into working on some stuff recently. basically the issue i'm having is that im getting a program to compile even though it shouldnt (at least i think).
i have a libgenericwipe project that contains a .cpp,.h,and .dev file in it. this libgenericwipe has not even been compiled to generate any static link libraries. in a separate folder i have another project for the executable im making.. this project includes the .h file for libgenericwipe. in the linker section for this project, i am linking to nothing. the program compiles without any errors or linker errors and i am able to call the genericwipe function even without linking to anything.. my guess is im missing something very obvious or im just being stupid. here are the contents of my project files.. killer.cpp #include <windows.h>
#include "c:\\c0ldshadow\\libgenericwipe\\genericwipe.h"
int main()
{
genericWipe("asd");
}genericwipe.h #ifndef GENERICWIPE_H #define GENERICWIPE_H #include "genericwipe.cpp" bool genericWipe(const char *); #endif genericwipe.cpp #include <windows.h>
#include <stdio.h>
#include <string.h>
bool genericWipe(const char *what)
{
//note i removed the code here since its not important for this issue
return true;
}maybe its just me but i swear that this program shouldnt compile.. i thought that the genericwipe project would need to be compiled into a static link library and then the killer.cpp would need to add this static link library file to the linker... i have done none of this, yet the code compiles and works fine... like i said before, i havent been coding in a while so maybe im just doing something blatantly stupid or whatever.. please note that this is issue no emergency but any advice would be great.. regards,--c0ldshadow
__________________
DeepTide The way is shut. It was made by those who are dead and the Dead keep it. The way is shut. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
I have no professional advice that i've gotten from books or anything, but my guess is that when a compiler sees a file in quotes on an include line it doesn't care what the extension is and just includes it as a header..
__________________
|
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
I would take a closer look at the following line in the genericWipe.h header file:
#include "genericwipe.cpp" Surely you see what is happening? btw, good to see you around again mon ami. EDIT: (ok, maybe I need to be more direct: try including "the other way around": include genericWipe.h in genericWipe.cpp.. get it now? )
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Can I suggest removing the path from your local #include?
|
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
Quote:
(In German, we speak of concrete and abstract paths, what are the English counterparts? It doesn't sound quite right for some reason...)
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Jun 2005
Posts: 86
Rep Power: 4
![]() |
This is where the problem is:
#include "genericwipe.cpp" Remove that line and instead, add genericwipe.cpp to your Makefile. Your new genericwipe.h should look like this: #ifndef GENERICWIPE_H #define GENERICWIPE_H bool genericWipe(const char *); #endif |
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
Quote:
|
|
|
|
|
|
|
#8 | |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
Quote:
. And reinforcing this point is never a bad thing. (and the #ifndef's to deter include loops are also all too often forgotten when a program is in it's tiny and insignificant beginnings... but then, when (not if!) the project grows, the beast rears it's terrible head and reveals it's horrid visage.Thank you Grumpy, this particular gnawing at the back of my mind has ceased. ![]() And, I must correct myself.. in German the 'pfad' it is also 'absolut' oder 'relativ'. In my defense, it is after midnight and it has been a difficult week ![]()
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty Last edited by stevengs; Sep 16th, 2005 at 5:16 PM. |
|
|
|
|
|
|
#9 |
|
Unverified User
Join Date: Jun 2005
Location: NJ
Posts: 23
Rep Power: 0
![]() |
wow. embarrassing mistake by me... i cannot believe i missed that lol. thanks for the advice. i havent been coding in a while and it shows.
peace,-c0ld
__________________
DeepTide The way is shut. It was made by those who are dead and the Dead keep it. The way is shut. |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Jun 2005
Posts: 86
Rep Power: 4
![]() |
By the way, the ifndef's won't save you linking errors either. For instance:
genericwipe.h
============
#ifndef GENERIC_WIPE_H
#define GENERIC_WIPE_H
void genericwipe(char *);
#include "genericwipe.cpp"
#endif
main.cpp
========
#include "genericwipe.h"
int main(void) {
...
}
someotherfile.cpp
===============
#include "genericwipe.h"
int somefunc(void) {
...
}This is why you should never put source code (or variable declarations) in header files . |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|