www.digitalmars.com         C & C++   DMDScript  

c++.command-line - linking problems

reply Tat Chan <Tat_member pathlink.com> writes:
I am having linking problems. When I compile straight C code with a Makefile, I
don't have any problems. However, once I put the -cpp switch for one of the
files (which will have C++ code, but at the moment, the file is pure C), I get
the following output

SMAKE  Program Maintenance Utility (Console) Version 7.21
Copyright (c) 1994-1995 Innovative Data Concepts Incorporated
Copyright (c) 1994-1995 Symantec Corporation
All Rights Reserved

c:\dev\dm\bin\sc -r -mn -3 -Ju -a8 -S -g  -D_CONSOLE -D_MT -D_WINDOWS -D
HAVE_USLEEP -DSQUID_CFG_DIR=\"./config\" -DSQUID_WGT_DIR=\"./wgtfiles\"  -DSQUID
_LOG_DIR=\"./logs\" -DSAVESAMP_DIR=\"./savesamp\" -DUSE_GUI    -DHAVE_CAPI=1 -If
:\capi20\include   -c -opsquid\main.obj main.c
perl ./scripts/xsrcs.pl -obj -prefix psquid sqexe.mak | perl ./scripts/m
kresp.pl        -symantec -link psquid\psquid.exe >psquid.lnk
echo pstnslib.lib sqlib.lib f:\capi20\lib\capi2032sym.lib  snn.l
ib WINMM.LIB KERNEL32.LIB GDI32.LIB USER32.LIB WSOCK32.LIB >>psquid.lnk
echo psquid.def >>psquid.lnk
c:\dev\dm\bin\LINK /CODEVIEW /NOI /DE /XN /NT /ENTRY:mainCRTStartup  /BA
S:4194304 /A:512   psquid.lnk
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

psquid\main.obj(main)
Error 42: Symbol Undefined _hKeyboardEvent
psquid\init.obj(init)
Error 42: Symbol Undefined _update_sys_stats
psquid\init.obj(init)
Error 42: Symbol Undefined _launch_gui
psquid\console.obj(console)
Error 42: Symbol Undefined ?makelog  YAXPAUlogid_t  W4EL_LEVELS_e  HPBDZZ (void
cdecl makelog(logid_t *,EL_LEVELS_e ,int ,char const *,...))
psquid\console.obj(console)
Error 42: Symbol Undefined ?sqFatalOSError  YAXPBD0H Z (void cdecl sqFatalOSErr
or(char const *,char const *,int ))
psquid\console.obj(console)
Error 42: Symbol Undefined ?reset_event  YAHPAX Z (int cdecl reset_event(void *
))
psquid\console.obj(console)
Error 42: Symbol Undefined ?errlog  3PAUlogid_t  A (logid_t *errlog)
pstnslib.lib(pstnsvcc)
Error 42: Symbol Undefined _get_sys_stats
pstnslib.lib(pstnsvcc)
Error 42: Symbol Undefined _get_chan_stats
sqlib.lib(errlog)
Error 42: Symbol Undefined _terminateDisplay
sqlib.lib(errlog)
Error 42: Symbol Undefined _addDispMessage

and so on ...

SMAKE fatal error: command "c:\dev\dm\bin\LINK" returned with error code 47
Stopping.
SMAKE fatal error: command "smake" returned with error code 2
Stopping.


all I did was add the -cpp flag for that particular file. The
compilation/linking worked fine before. What could be wrong?
Do I need to use the linker in a different way for C++ files?
Sep 03 2002
parent reply "Walter" <walter digitalmars.com> writes:
C++ changes the way symbols are named, which can cause undefined symbol
errors when linked with things compiled with the C compiler. Try wrapping
your C header files with extern "C" { }

"Tat Chan" <Tat_member pathlink.com> wrote in message
news:al3u5c$au5$1 digitaldaemon.com...
 I am having linking problems. When I compile straight C code with a
Makefile, I
 don't have any problems. However, once I put the -cpp switch for one of
the
 files (which will have C++ code, but at the moment, the file is pure C), I
get
 the following output

 SMAKE  Program Maintenance Utility (Console) Version 7.21
 Copyright (c) 1994-1995 Innovative Data Concepts Incorporated
 Copyright (c) 1994-1995 Symantec Corporation
 All Rights Reserved

 c:\dev\dm\bin\sc -r -mn -3 -Ju -a8 -S -g  -D_CONSOLE -D_MT -D_WINDOWS -D
AVE_USLEEP -DSQUID_CFG_DIR=\"./config\" -DSQUID_WGT_DIR=\"./wgtfiles\" -DSQ UID

G_DIR=\"./logs\" -DSAVESAMP_DIR=\"./savesamp\" -DUSE_GUI    -DHAVE_CAPI=1 -I
f
 :\capi20\include   -c -opsquid\main.obj main.c
 perl ./scripts/xsrcs.pl -obj -prefix psquid sqexe.mak | perl ./scripts/m
 kresp.pl        -symantec -link psquid\psquid.exe >psquid.lnk
 echo pstnslib.lib sqlib.lib f:\capi20\lib\capi2032sym.lib  snn.l
 ib WINMM.LIB KERNEL32.LIB GDI32.LIB USER32.LIB WSOCK32.LIB >>psquid.lnk
 echo psquid.def >>psquid.lnk
 c:\dev\dm\bin\LINK /CODEVIEW /NOI /DE /XN /NT /ENTRY:mainCRTStartup  /BA
 S:4194304 /A:512   psquid.lnk
 OPTLINK (R) for Win32  Release 7.50B1
 Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

 psquid\main.obj(main)
 Error 42: Symbol Undefined _hKeyboardEvent
 psquid\init.obj(init)
 Error 42: Symbol Undefined _update_sys_stats
 psquid\init.obj(init)
 Error 42: Symbol Undefined _launch_gui
 psquid\console.obj(console)
 Error 42: Symbol Undefined ?makelog  YAXPAUlogid_t  W4EL_LEVELS_e  HPBDZZ
(void
 cdecl makelog(logid_t *,EL_LEVELS_e ,int ,char const *,...))
 psquid\console.obj(console)
 Error 42: Symbol Undefined ?sqFatalOSError  YAXPBD0H Z (void cdecl
sqFatalOSErr
 or(char const *,char const *,int ))
 psquid\console.obj(console)
 Error 42: Symbol Undefined ?reset_event  YAHPAX Z (int cdecl
reset_event(void *
 ))
 psquid\console.obj(console)
 Error 42: Symbol Undefined ?errlog  3PAUlogid_t  A (logid_t *errlog)
 pstnslib.lib(pstnsvcc)
 Error 42: Symbol Undefined _get_sys_stats
 pstnslib.lib(pstnsvcc)
 Error 42: Symbol Undefined _get_chan_stats
 sqlib.lib(errlog)
 Error 42: Symbol Undefined _terminateDisplay
 sqlib.lib(errlog)
 Error 42: Symbol Undefined _addDispMessage

 and so on ...

 SMAKE fatal error: command "c:\dev\dm\bin\LINK" returned with error code
47
 Stopping.
 SMAKE fatal error: command "smake" returned with error code 2
 Stopping.


 all I did was add the -cpp flag for that particular file. The
 compilation/linking worked fine before. What could be wrong?
 Do I need to use the linker in a different way for C++ files?
Sep 04 2002
parent Tat Chan <Tat_member pathlink.com> writes:
Hi Walter,

I decided to add the following code to all .h files (this seems to be a standard
way of mixing C/C++ code)

#ifdef __cplusplus
extern "C" {
#endif

// original code

#ifdef __cplusplus
}
#endif

I have managed to compile a pure C file with the -cpp switch. I had to define
some function prototypes in the .h file that were previously undefined (mostly
dealing functions that were declared as extern in other files). So I guess I
might have to do more of that for each C file I am compiling with the -cpp
switch. But I can now do use vectors in the original C code (or at least I can
compile and link).

I had always assumed that it would mixing C and C++ code would be a rather
trivial process. Well, compilation is, but definitely not the linking process.

Thanks for all the help given.

Tat

In article <al58vu$1542$1 digitaldaemon.com>, Walter says...
C++ changes the way symbols are named, which can cause undefined symbol
errors when linked with things compiled with the C compiler. Try wrapping
your C header files with extern "C" { }
Sep 04 2002