Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Multiple Source Files

Author
Message
WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 14th Feb 2010 07:16
I have a Main.cpp and another source file that I created called QuickSort.c I have a header file for QuickSort.c called QuickSort.h. I have included the header in both QuickSort.c and in the Main.cpp. I have #pragma once in QuickSort.h. I call a function called QuickSort() in QuickSort.c in the DarkGDK function in Main.cpp. Whenever I try to compile, the compilation succeeds, but I keep getting a linker error. It keeps telling me the following:

LINK : Debug\Collision Detection.exe not found or not built by the last incremental link; performing full link
Main.obj : error LNK2019: unresolved external symbol "void __cdecl QuickSort(int * const,int)" (?QuickSort@@YAXQAHH@Z) referenced in function "void __cdecl DarkGDK(void)" (?DarkGDK@@YAXXZ)

I can't figure out what is wrong. What is the difference between what I am doing and what the guy who created Dark Invaders is doing? I can't tell the difference. His source files, when compiled, yield no linker errors while mine do.
Aldur
17
Years of Service
User Offline
Joined: 8th Oct 2007
Location: Melbourne, Australia
Posted: 14th Feb 2010 08:03
Could you please post some code so we can see what a possible cause could be? There may be a simple typo somewhere or perhaps something completely different.

We won't know until we see some source code.

WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 14th Feb 2010 08:38 Edited at: 14th Feb 2010 08:41
Nevermind. I fixed the problem. I fixed it by including DarkSDK.h or DarkGDK.h in QuickSort.c. I am guessing that this solved the problem because including either of those header files included the declaration/prototype of the DarkGDK() function, the function in which one of the functions in QuickSort.c is called. It seems that not only do you need to include the prototypes of the functions that you want to call, but you also need to include the prototype of the function, in which those functions will be called, in the source file that those functions were defined. Since I wanted to call the function QuickSort() in QuickSort.c in the function DarkGDK() (Note that DarkGDK() is defined in Main.cpp), not only do I need the prototype of QuickSort() in Main.cpp, but I also need the prototype of DarkGDK(), which is the function in which QuickSort() will be called, in the source file that QuickSort() is defined, which is QuickSort.c. Note that in order to not get tons of errors from the compiler when including the DarkGDK() prototype in my case, I had to convert my .c file to a .cpp file.

Login to post a reply

Server time is: 2024-11-20 03:44:20
Your offset time is: 2024-11-20 03:44:20