MSVC++ linking error

Hi all. I’m trying to build a ROOT application in MSVC++ (vs 2008). I’m doing this because I need to link against some C libraries as well. I’m testing with this basic test (found in these forums).

[code]#include <Windows4Root.h>

#include
#include “TH1D.h”
#include “TApplication.h”

using namespace std;

int main( int argc, char** argv) {
TApplication app(“fctest”, &argc, argv);

TH1D* myhisto=new TH1D(“myhisto”,“myhisto”,10,0,10);
myhisto->Fill(3);
myhisto->Draw();
cout<<“Program Finished”<< endl;
app.Run();
return 0;
}[/code]

I get the following error:

1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall TH1D::TH1D(char const *,char const *,int,double,double)" (??0TH1D@@QAE@PBD0HNN@Z) referenced in function _main 1>C:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\PixieROOT\Debug\PixieROOT.exe : fatal error LNK1120: 1 unresolved externals 1>Build log was saved at "file://c:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\PixieROOT\PixieROOT\Debug\BuildLog.htm" 1>PixieROOT - 2 error(s), 1 warning(s)

looking at the makefile (nmake, .win32) It looks like it does rootcint on some files to create a dictionary of some sort. Is this something I need to do, and can it be done easily from with in Visual Studio?

Hi,

For simple application like the one you describe, there is no need to generate any dictionary. You only need to link with the ROOT libraries. For example, the unresolved external symbol you see comes from libHist.lib

Cheers, Bertrand.

Thanks, that was the issue in this case. I’ll go back to some of the other codes I was testing before I was trying this simplest test case.

Ok, I’ve split up the numberEntry.C tutorial file into a main.cpp which just instantiates the MyMainFrame class and a main_window.h which contains the declarations, and main_window.cpp which contains the implementation details. (I did this because this is how I want to start implementing a GUI for my own purposes.) I now get the following error when linking (I’m linking against libCore, libHist [didn’t change after getting last example to work], libGraf, libGui and libGpad):

1>Linking... 1>main_window.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall MyMainFrame::ShowMembers(class TMemberInspector &,char *)" (?ShowMembers@MyMainFrame@@UAEXAAVTMemberInspector@@PAD@Z) 1>main_window.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall MyMainFrame::Streamer(class TBuffer &)" (?Streamer@MyMainFrame@@UAEXAAVTBuffer@@@Z) 1>main_window.obj : error LNK2019: unresolved external symbol "public: static class TClass * __cdecl MyMainFrame::Class(void)" (?Class@MyMainFrame@@SAPAVTClass@@XZ) referenced in function "public: virtual class TClass * __thiscall MyMainFrame::IsA(void)const " (?IsA@MyMainFrame@@UBEPAVTClass@@XZ) 1>C:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\PixieROOT\Debug\PixieROOT.exe : fatal error LNK1120: 3 unresolved externals

Hi,

If you really need to generate dictionary (using the ClassDef macro), you have to use a LinkDef.h file, and add a custom build step. For example add the following line in Build Events, Pre-Link Event:

And add your_dictionary.cpp in your project.
If you don’t know how to do it, just post your code, I will modify it.
And BTW, maybe it would be simpler to use a nmake makefile…

Cheers, Bertrand.

I decided to go with using nmake files as you sugested, and everything has gone smoothly since. Thanks.