Linking problem with Visual C++ 2005 Express Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
PhoenixPl
I live to help wx-kind
I live to help wx-kind
Posts: 179
Joined: Wed Feb 15, 2006 9:26 am

Linking problem with Visual C++ 2005 Express

Post by PhoenixPl »

Hello,

I have a linking problem with library build in Visual C++ 2005 Express. The error message for simple empty frame is:

Code: Select all

main.obj:: error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall wxString::wxString(wchar_t const *)" (__imp_??0wxString@@QAE@PB_W@Z) referenced in function "public: __thiscall MyFrame::MyFrame(class wxFrame *)" (??0MyFrame@@QAE@PAVwxFrame@@@Z)
main.obj:: error LNK2019: unresolved external symbol "__declspec(dllimport) wchar_t const * const wxFrameNameStr" (__imp_?wxFrameNameStr@@3QB_WB) referenced in function "public: __thiscall MyFrame::MyFrame(class wxFrame *)" (??0MyFrame@@QAE@PAVwxFrame@@@Z)
app.obj:: error LNK2001: unresolved external symbol "public: virtual bool __thiscall wxApp::Initialize(int &,wchar_t * *)" (?Initialize@wxApp@@UAE_NAAHPAPA_W@Z)
bin\Release\aa.exe:: fatal error LNK1120: 3 unresolved externals
:: === Build finished: 4 errors, 0 warnings ===
I have compiled the library exactly the same way as Microsoft C++ Toolkit 2003:

Code: Select all

nmake -f makefile.vc UNICODE=0 BUILD=release SHARED=1 MONOLITHIC=1 RUNTIME_LIBS=static USE_RTTI=0 USE_EXCEPTIONS=1 VENDOR=ev
I don't have any problems with Microsoft C++ Toolkit, but C++ 2005 Express just doesn't seam to like those settings. Any ideas what can it be?

Using:
Windows XP sp2
Code::Blocks
wxWidgets 2.7.1
dsilvia
Earned some good credits
Earned some good credits
Posts: 145
Joined: Sun May 29, 2005 3:42 pm
Location: Bettendorf, Iowa, USA (aka, BFE)

Re: Linking problem with Visual C++ 2005 Express

Post by dsilvia »

PhoenixPl wrote:Hello,

I have a linking problem with library build in Visual C++ 2005 Express. The error message for simple empty frame is:

Code: Select all

main.obj:: error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall wxString::wxString(wchar_t const *)" (__imp_??0wxString@@QAE@PB_W@Z) referenced in function "public: __thiscall MyFrame::MyFrame(class wxFrame *)" (??0MyFrame@@QAE@PAVwxFrame@@@Z)
main.obj:: error LNK2019: unresolved external symbol "__declspec(dllimport) wchar_t const * const wxFrameNameStr" (__imp_?wxFrameNameStr@@3QB_WB) referenced in function "public: __thiscall MyFrame::MyFrame(class wxFrame *)" (??0MyFrame@@QAE@PAVwxFrame@@@Z)
app.obj:: error LNK2001: unresolved external symbol "public: virtual bool __thiscall wxApp::Initialize(int &,wchar_t * *)" (?Initialize@wxApp@@UAE_NAAHPAPA_W@Z)
bin\Release\aa.exe:: fatal error LNK1120: 3 unresolved externals
:: === Build finished: 4 errors, 0 warnings ===
I have compiled the library exactly the same way as Microsoft C++ Toolkit 2003:

Code: Select all

nmake -f makefile.vc UNICODE=0 BUILD=release SHARED=1 MONOLITHIC=1 RUNTIME_LIBS=static USE_RTTI=0 USE_EXCEPTIONS=1 VENDOR=ev
I don't have any problems with Microsoft C++ Toolkit, but C++ 2005 Express just doesn't seam to like those settings. Any ideas what can it be?

Using:
Windows XP sp2
Code::Blocks
wxWidgets 2.7.1
Here's the output from a make for a simple app in DialogBlocks:

Code: Select all

----------------------- Configuration: VC++ Debug -----------------------
In directory: D:\Projects\DialogBlocks\doodling
nmake /nologo -f makefile.vc CONFIG=debug all
	if not exist DebugMSW mkdir DebugMSW
	cl.exe /c /nologo /TP /FoDebugMSW\XpmApp.obj /DNOPCH /DWIN32 /D__WXMSW__ /D_WINDOWS /D__WXDEBUG__ /D_DEBUG /Zi /MDd /Od /GR /EHsc /W4 /I"C:\wxWidgets-2.6.3/include" /I"C:\wxWidgets-2.6.3/contrib/include" /I"C:\wxWidgets-2.6.3/lib/vc_lib/mswd" /I"C:\Program Files\Microsoft Visual Studio 8\vc\include" /I"C:\Program Files\Microsoft Visual Studio 8\vc\PlatformSDK\include" /I"C:\Program Files\Microsoft Platform SDK\include" XpmApp.cpp
XpmApp.cpp
d:\projects\dialogblocks\doodling\xpmapp.cpp(96) : warning C4702: unreachable code
	cl.exe /c /nologo /TP /FoDebugMSW\XpmDialog.obj /DNOPCH /DWIN32 /D__WXMSW__ /D_WINDOWS /D__WXDEBUG__ /D_DEBUG /Zi /MDd /Od /GR /EHsc /W4 /I"C:\wxWidgets-2.6.3/include" /I"C:\wxWidgets-2.6.3/contrib/include" /I"C:\wxWidgets-2.6.3/lib/vc_lib/mswd" /I"C:\Program Files\Microsoft Visual Studio 8\vc\include" /I"C:\Program Files\Microsoft Visual Studio 8\vc\PlatformSDK\include" /I"C:\Program Files\Microsoft Platform SDK\include" XpmDialog.cpp
XpmDialog.cpp
XpmDialog.cpp(97) : warning C4189: 'itemDialog1' : local variable is initialized but not referenced
	rc.exe /foDebugMSW\xpm.res /DNOPCH /DWIN32 /D__WXMSW__ /D_WINDOWS /D__WXDEBUG__ /D_DEBUG /I "C:\wxWidgets-2.6.3/include" /I "C:\wxWidgets-2.6.3/contrib/include" /I "C:\wxWidgets-2.6.3/lib/vc_lib/mswd" /I "C:\Program Files\Microsoft Visual Studio 8\vc\include" /I "C:\Program Files\Microsoft Visual Studio 8\vc\PlatformSDK\include" /I "C:\Program Files\Microsoft Platform SDK\include" xpm.rc
	link /OUT:DebugMSW\xpm.exe /LIBPATH:"C:\wxWidgets-2.6.3/lib/vc_lib" /LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\vc\lib" /LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\vc\PlatformSDK\lib" /LIBPATH:"C:\Program Files\Microsoft Platform SDK\lib" /nologo /SUBSYSTEM:WINDOWS /machine:i386 /DEBUG @C:\DOCUME~1\dsilvia\LOCALS~1\Temp\nm1A2.tmp
Done.

0 errors, 2 warnings
And this is the makefile.vc it used:

Code: Select all

### Begin DialogBlocks generated body
################################################################################
# Makefile generated by DialogBlocks                                           #
#
# Available configurations:
# debug
################################################################################

CONFIG=debug

# debug
!if "$(CONFIG)" == "debug"

WXWIN=C:\wxWidgets-2.6.3
CXX=cl.exe
RESCOMP=rc.exe
OUTPUTPATH=DebugMSW
OBJECTPATH=DebugMSW
CPPFLAGS=/DNOPCH /DWIN32 /D__WXMSW__ /D_WINDOWS /D__WXDEBUG__ /D_DEBUG
WARNINGFLAGS=/W4
OPTFLAGS=/MDd /Od /GR /EHsc
DEBUGFLAGS=/Zi
LINKERFLAGS=/nologo /SUBSYSTEM:WINDOWS /machine:i386 /DEBUG
LIBS=wxmsw26d_core.lib wxbase26d.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib wxregexd.lib wxmsw26d_adv.lib wxmsw26d_html.lib wxmsw26d_xrc.lib wxmsw26d_gl.lib wxbase26d_net.lib wxbase26d_xml.lib wxexpatd.lib kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib opengl32.lib
CPPINC=/I"$(WXWIN)/include" /I"$(WXWIN)/contrib/include" /I"$(WXWIN)/lib/vc_lib/mswd" /I"C:\Program Files\Microsoft Visual Studio 8\vc\include" /I"C:\Program Files\Microsoft Visual Studio 8\vc\PlatformSDK\include" /I"C:\Program Files\Microsoft Platform SDK\include"
LIBPATH=/LIBPATH:"$(WXWIN)/lib/vc_lib" /LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\vc\lib" /LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\vc\PlatformSDK\lib" /LIBPATH:"C:\Program Files\Microsoft Platform SDK\lib"
RESPATH=/I "$(WXWIN)/include" /I "$(WXWIN)/contrib/include" /I "$(WXWIN)/lib/vc_lib/mswd" /I "C:\Program Files\Microsoft Visual Studio 8\vc\include" /I "C:\Program Files\Microsoft Visual Studio 8\vc\PlatformSDK\include" /I "C:\Program Files\Microsoft Platform SDK\include"
PROGRAM=xpm.exe
RCFILEOBJ=xpm.res
RCFILESRC=xpm.rc
!endif

OBJECTS=$(OBJECTPATH)\XpmApp.obj $(OBJECTPATH)\XpmDialog.obj $(OBJECTPATH)\$(RCFILEOBJ)

all:	$(OBJECTPATH)

$(OBJECTPATH):
	-if not exist $(OBJECTPATH) mkdir $(OBJECTPATH)

clean:
	-if exist $(OBJECTPATH)\*.obj del $(OBJECTPATH)\*.obj
	-if exist $(OBJECTPATH)\*.res del $(OBJECTPATH)\*.res
	-if exist $(OUTPUTPATH)\$(PROGRAM) del $(OUTPUTPATH)\$(PROGRAM)
	-if exist $(OUTPUTPATH)\xpm.ilk del $(OUTPUTPATH)\xpm.ilk
	-if exist $(OUTPUTPATH)\xpm.pdb del $(OUTPUTPATH)\xpm.pdb

help:
	@echo "Usage: make -f makefile.vc CONFIG=[debug] [all|clean|help]"

### Targets ####

all:	$(OUTPUTPATH)\$(PROGRAM)

$(OUTPUTPATH)\$(PROGRAM):	$(OBJECTS)
	link /OUT:$@ $(LIBPATH) $(LINKERFLAGS) @<<
	$(OBJECTS) $(LIBS)
<<

$(OBJECTPATH)\$(RCFILEOBJ):	$(RCFILESRC)
	$(RESCOMP) /fo$@ $(CPPFLAGS) $(RESPATH) $**

$(OBJECTPATH)\XpmApp.obj:	XpmApp.cpp XpmApp.h XpmDialog.h pasteElmers32.xpm
	$(CXX) /c /nologo /TP /Fo$@ $(CPPFLAGS) $(DEBUGFLAGS) $(OPTFLAGS) $(WARNINGFLAGS) $(CPPINC) XpmApp.cpp

$(OBJECTPATH)\XpmDialog.obj:	XpmDialog.cpp XpmDialog.h pasteElmers.xpm
	$(CXX) /c /nologo /TP /Fo$@ $(CPPFLAGS) $(DEBUGFLAGS) $(OPTFLAGS) $(WARNINGFLAGS) $(CPPINC) XpmDialog.cpp

### End DialogBlocks generated body
DialogBlocks makes easy work of building wxWidgets (for any platform) and any applications (for any platform). It will generate either a makefile.vc or the .sln and .vcproj files (or both) for Visual Studio 2005. If you build using VC++ Project and compiler verision 8, the .vcproj file generated can then be opened in Visual Studio (devenv.exe) and run and debugged from there. It's really quite handy!;)

You can check out a fully functional version of DialogBlocks (no time limit) at:

http://www.anthemion.co.uk/dialogblocks/

HTH:

Dave S.

wxMS_developers
PhoenixPl
I live to help wx-kind
I live to help wx-kind
Posts: 179
Joined: Wed Feb 15, 2006 9:26 am

Post by PhoenixPl »

Thanks for this dsilvia, but it's not what I was looking for. It still doesn't explain why I can't link my api with wx2.7.2 and I can with wx2.6.3. I'm still using the same options, so something has changed in wx2.7.2 and I would like to know how to solve it without getting used to new IDE (which I have noticed is great). I prefer Code::Blocks, because I'm not using only wxWidgets and they still have good achievements.
rjmyst3
Knows some wx things
Knows some wx things
Posts: 49
Joined: Tue Oct 10, 2006 7:02 pm
Contact:

Post by rjmyst3 »

looks like the missing functions all use wchar_t - to me, that means that the problem is either related to Unicode or to treating wchar_t as a built in type.

I'm leaning toward the latter, as I've had similar problems.

The default in VC03 is to not treat wchar_t as built in, the default in VC05 is to treat it as built in.

If you are in Code::Blocks, in the Compiler|Other Options tab type the following:
/Zc:wchar_t-

This will tell VC05 to not treat wchar_t as a built in type, and hopefully it will be consistent with your wxWidgets build.
PhoenixPl
I live to help wx-kind
I live to help wx-kind
Posts: 179
Joined: Wed Feb 15, 2006 9:26 am

Post by PhoenixPl »

Thanks rjmyst3. You saved my live. :lol:
Post Reply