.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   compiling .c and .cpp files altogether ? (http://forums.bots-united.com/showthread.php?t=3193)

Pierre-Marie Baty 13-12-2004 00:15

compiling .c and .cpp files altogether ?
 
I've realized my old dream: porting all my bot source code to ANSI C. It's now all .c files, at the exception of interface.cpp which contains the HL engine interfacing functions and stuff.

But the problem, is that the linker can't seem to find external variables and functions in both situations! I mean that when something is declared in a .c file it can't be accessed from the .cpp file (even if you declare it extern) and vice versa...

look at the output
Quote:

--------------------Configuration: HL:CounterStrike - Win32 Release--------------------
Compiling resources...
Compiling...
bmpfile.c
dxffile.c
mapdata.c
pathmachine.c
console.c
display.c
lrand.c
math.c
mfile.c
util.c
bot.c
bot_cognition.c
bot_combat.c
bot_start.c
interface.cpp
bot_body.c
bot_chat.c
bot_ears.c
bot_eyes.c
bot_navigation.c
weapons.c
Updating resources...
Linking...
Creating library ..\../racc.lib and object ..\../racc.exp
mapdata.obj : error LNK2001: unresolved external symbol _PointBelongsToWorld
bot_body.obj : error LNK2001: unresolved external symbol _PointBelongsToWorld
mapdata.obj : error LNK2001: unresolved external symbol _PlayerTestHull
util.obj : error LNK2001: unresolved external symbol _PlayerTestHull
bot_body.obj : error LNK2001: unresolved external symbol _PlayerTestHull
mapdata.obj : error LNK2001: unresolved external symbol _PlayerTestLine
bot_body.obj : error LNK2001: unresolved external symbol _PlayerTestLine
bot_eyes.obj : error LNK2001: unresolved external symbol _PlayerTestLine
bot_navigation.obj : error LNK2001: unresolved external symbol _PlayerTestLine
bot_navigation.obj : error LNK2001: unresolved external symbol _TestVisibility
mapdata.obj : error LNK2001: unresolved external symbol _TestVisibility
util.obj : error LNK2001: unresolved external symbol _TestVisibility
bot_combat.obj : error LNK2001: unresolved external symbol _TestVisibility
bot_eyes.obj : error LNK2001: unresolved external symbol _TestVisibility
util.obj : error LNK2001: unresolved external symbol _IsLiquid
bot_body.obj : error LNK2001: unresolved external symbol _IsLiquid
bot_navigation.obj : error LNK2001: unresolved external symbol _IsLiquid
bot.obj : error LNK2001: unresolved external symbol _FindMaterialType
bot_ears.obj : error LNK2001: unresolved external symbol _FindMaterialType
interface.obj : error LNK2001: unresolved external symbol "char * racc_version" (?racc_version@@3PADA)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl DllAttaching(void)" (?DllAttaching@@YAXXZ)
interface.obj : error LNK2001: unresolved external symbol "struct server_s Server" (?Server@@3Userver_s@@A)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl DllDetaching(void)" (?DllDetaching@@YAXXZ)
interface.obj : error LNK2001: unresolved external symbol "struct entity_s * entities" (?entities@@3PAUentity_s@@A)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl PlayClientSoundsForBots(struct player_s *)" (?PlayClientSoundsForBots@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl ShowTheWayAroundToBots(struct player_s *)" (?ShowTheWayAroundToBots@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotAct(struct player_s *)" (?BotAct@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotThink(struct player_s *)" (?BotThink@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotSense(struct player_s *)" (?BotSense@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "float __cdecl RandomFloat(float,float)" (?RandomFloat@@YAMMM@Z)
interface.obj : error LNK2001: unresolved external symbol "int player_count" (?player_count@@3HA)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotCreate(struct player_s *)" (?BotCreate@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "struct profile_s * __cdecl FindUnusedBotProfile(void)" (?FindUnusedBotProfile@@YAPAUprofile_s@@XZ)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotHALSaveBrain(struct player_s *)" (?BotHALSaveBrain@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotNavSaveBrain(struct player_s *)" (?BotNavSaveBrain@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotReset(struct player_s *)" (?BotReset@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "unsigned char __cdecl VectorIsNull(struct vec_s)" (?VectorIsNull@@YAEUvec_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "struct entity_s * __cdecl FindEntityByString(struct entity_s *,char,char const *)" (?FindEntityByString@@YAPAUentity_s@@PAU1@DPBD@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl APlayerHasConnected(struct player_s *)" (?APlayerHasConnected@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "float __cdecl DistanceBetween(struct vec_s,struct vec_s)" (?DistanceBetween@@YAMUvec_s@@0@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl TerminateOnError(char const *,...)" (?TerminateOnError@@YAXPBDZZ)
interface.obj : error LNK2001: unresolved external symbol "struct weapon_s * __cdecl FindPlayerWeaponByModel(struct player_s *,char const *)" (?FindPlayerWeaponByModel@@YAPAUweapon_s@@PAUplayer _s@@PBD@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BuildPlayerReferential(struct vec_s,struct player_s *)" (?BuildPlayerReferential@@YAXUvec_s@@PAUplayer_s@@@ Z)
interface.obj : error LNK2001: unresolved external symbol "struct player_s * pListenserverPlayer" (?pListenserverPlayer@@3PAUplayer_s@@A)
interface.obj : error LNK2001: unresolved external symbol "float __cdecl WrapAngle(float)" (?WrapAngle@@YAMM@Z)
interface.obj : error LNK2001: unresolved external symbol "struct vec_s __cdecl VectorSubstract(struct vec_s,struct vec_s)" (?VectorSubstract@@YA?AUvec_s@@U1@0@Z)
interface.obj : error LNK2001: unresolved external symbol "struct mission_s Mission" (?Mission@@3Umission_s@@A)
interface.obj : error LNK2001: unresolved external symbol "float __cdecl ProcessTime(void)" (?ProcessTime@@YAMXZ)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl TheServerHasJustStarted(void)" (?TheServerHasJustStarted@@YAXXZ)
interface.obj : error LNK2001: unresolved external symbol "void * __cdecl SAFE_Z_malloc(unsigned int)" (?SAFE_Z_malloc@@YAPAXI@Z)
interface.obj : error LNK2001: unresolved external symbol "struct game_config_s GameConfig" (?GameConfig@@3Ugame_config_s@@A)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl SAFE_free(void *)" (?SAFE_free@@YAXPAX@Z)
interface.obj : error LNK2001: unresolved external symbol "void * __cdecl SAFE_realloc(void *,unsigned int)" (?SAFE_realloc@@YAPAXPAXI@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl APlayerHasDisconnected(struct player_s *)" (?APlayerHasDisconnected@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "struct player_s * players" (?players@@3PAUplayer_s@@A)
interface.obj : error LNK2001: unresolved external symbol "struct debug_level_s DebugLevel" (?DebugLevel@@3Udebug_level_s@@A)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl DispatchSound(char const *,struct vec_s,float,float)" (?DispatchSound@@YAXPBDUvec_s@@MM@Z)
interface.obj : error LNK2001: unresolved external symbol "char const * __cdecl GetField(char const *,int)" (?GetField@@YAPBDPBDH@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl PlayBulletSoundsForBots(struct player_s *)" (?PlayBulletSoundsForBots@@YAXPAUplayer_s@@@Z)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotFeedEar(struct player_s *,struct sound_s *,struct vec_s,float)" (?BotFeedEar@@YAXPAUplayer_s@@PAUsound_s@@Uvec_s@@M @Z)
interface.obj : error LNK2001: unresolved external symbol "struct sound_s * __cdecl FindSoundByFilename(char const *)" (?FindSoundByFilename@@YAPAUsound_s@@PBD@Z)
interface.obj : error LNK2001: unresolved external symbol "char * __cdecl UpperCase(char const *)" (?UpperCase@@YAPADPBD@Z)
interface.obj : error LNK2001: unresolved external symbol "int __cdecl ServerConsole_printf(char const *,...)" (?ServerConsole_printf@@YAHPBDZZ)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotIssueClientCommand(struct player_s *,char const *,...)" (?BotIssueClientCommand@@YAXPAUplayer_s@@PBDZZ)
interface.obj : error LNK2001: unresolved external symbol "void __cdecl BotSetIdealYaw(struct player_s *,float)" (?BotSetIdealYaw@@YAXPAUplayer_s@@M@Z)
interface.obj : error LNK2001: unresolved external symbol "char * racc_welcometext" (?racc_welcometext@@3PADA)
interface.obj : error LNK2001: unresolved external symbol "long __cdecl RandomLong(long,long)" (?RandomLong@@YAJJJ@Z)
interface.obj : error LNK2001: unresolved external symbol "int __cdecl ServerCommand(int,char * *)" (?ServerCommand@@YAHHPAPAD@Z)
interface.obj : error LNK2001: unresolved external symbol "char const * __cdecl TeamNameOf(struct player_s *)" (?TeamNameOf@@YAPBDPAUplayer_s@@@Z)
bot_chat.obj : error LNK2001: unresolved external symbol _PlayerStopTalking
bot_chat.obj : error LNK2001: unresolved external symbol _PlayerStartTalking
bot_eyes.obj : error LNK2001: unresolved external symbol _GetBonePosition
bot_navigation.obj : error LNK2001: unresolved external symbol _IsThinAir
..\../racc.dll : fatal error LNK1120: 60 unresolved externals
Error executing link.exe.
racc.dll - 74 error(s), 0 warning(s)
Does anybody have an explanation ? Don't tell me it's impossible, argh... no...

sfx1999 13-12-2004 00:39

Re: compiling .c and .cpp files altogether ?
 
Maybe you have to wrap your C files like this:

Code:

#ifdef cplusplus
    extern "C"
    {
    #endif
   
    //the code
   
    #ifdef cplusplus
    }
    #endif


Pierre-Marie Baty 13-12-2004 01:42

Re: compiling .c and .cpp files altogether ?
 
sfx I love you!

erm, right. In the very spiritual sense of the term, I mean :|

btw, it's not cplusplus but __cplusplus.

sfx1999 13-12-2004 04:18

Re: compiling .c and .cpp files altogether ?
 
I put cplusplus. So, it worked then?

Pierre-Marie Baty 13-12-2004 05:41

Re: compiling .c and .cpp files altogether ?
 
Yeah, but instead of wrapping all the .c files with it, I only needed to wrap the function prototypes and the global variables declarations. All the rest can remain unchanged.

Thanks for the hint, anyway :)

sfx1999 13-12-2004 05:45

Re: compiling .c and .cpp files altogether ?
 
Well, I had no clue if it was going to work or not, but I remembered it was in Botman's patches for GCC.


All times are GMT +2. The time now is 12:19.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.