Jump to content
Tuts 4 You

Link Error [c++]


Guest [n]ewcom3R

Recommended Posts

Guest [n]ewcom3R
Posted (edited)

Hi all,

I have a big problem!! I wanted to create a C++ app. I have a resource file with dialog.. I defined my functions in a file named threads.cpp and the prototypes in a file named threads.hpp. The main dialog was defined in main.cpp

when i wanted to compile the project there were serveral errors:

main.obj ERROR LNK2005

main.obj ERROR LNK2019

here are my files:

threads.cpp

#include "fstream"using namespace std;bool CreatePhPLoaderFile(char* PhpFileName){....
}

threads.hpp

#include <windows.h>#include "Threads.cpp"
#include "resource.h"HINSTANCE hInst;
HWND dlgMain;bool CreatePhPLoaderFile(char* PhpFileName);

and now my main.cpp


<div class='codetop'>CODE<div class='codemain' style='height:200px;white-space:pre;overflow:auto'>#include "Threads.hpp"BOOL CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam).....</div></div>
Edited by [n]ewcom3R
Posted

G-Sis how are we supposed to know what's wrong with it :o

You stripped most of the source, I mean I can understand you don't want to show around your code but we're unable to help you without knowing anything.

You should at least say what the exact error is (I guess you're using VC++ and it definately tells you what's wrong, at least most of the time) and where it happens (with the source code in that specific line !)...

Otherwise, if this is the actual source, you need to start again, this time with HTML

Guest [n]ewcom3R
Posted

Sorry !

There is my build log.

-------------- Build: default in PHP Loader ---------------
Linking executable: PHP Loader.exe
main.obj : error LNK2005: "bool __cdecl CreatePhPLoaderFile(char *)" (?CreatePhPLoaderFile@@YA_NPAD@Z) already defined in Threads.obj
main.obj : error LNK2019: unresolved external symbol __imp__ShellExecuteA@24 referenced in function "int __stdcall DlgProc(struct HWND__ *,unsigned int,unsigned int,long)" (?DlgProc@@YGHPAUHWND__@@IIJ@Z)
PHP Loader.exe : fatal error LNK1120: 1 unresolved externals
Process terminated with status 1 (0 minutes, 0 seconds)

My code is OK. There Error appears only if i adds the code witch is define in my threads.cpp. could it be that windows.h and fstream are incompatible? If I don't use fstream it works well!

Posted

Hum, the first error is obvious I guess, you defined it twice.

The trick here is to define the function prototype of CreatePhPLoaderFile _before_ importing the .cpp that contains the actual code.

I'm not really familiar with all the .h stuff, I just stumbled upon that behaviour and played around a little. I don't know if its only VC++ who's acting like that or if this is usual among all C[++] compilers (ie. defined as some sort of standard ?)...

As for the second error, you seem to be missing a header for ShellExecuteA. I was able to compile an app using that API with those 2 includes:

#include <windows.h>

#include <stdlib.h>

Otherwise you might have screwed your global setting, what with unicode and ascii. Maybe it's fstream.h ? no clue...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...