Crash of compiled library on Windows Vista

Dear Christian,
You may want to install
dependencywalker.com/

It can not fix the issue. However, it can show you where your problem comes from and when.

Dear Valeri,

Thank you for this info, I will test dependencywalker.

Please note that “R&ROOT” is not one application. Windows users download and install the ROOT binary compiled
with VC++ and the R binary compiled with MinGW. R allows developers to create “packages” which can contain
C/C++ source code, which is mostly compiled with MinGW, too.

Since my package contains C++ source code dependent on ROOT I need to compile it with VC++, however R cannot
find the ROOT libraries when compiling with /MD so I need to compile with /MT which works on WinXP.
However, it does not work on Vista therefore I am trying to compile ROOT also with option /MT with the thankful
help of Bertrand. I will se how far we get.

Best regads
Christian

Dear Christian,

[quote=“cstrato”]…Please note that “R&ROOT” is not one application.
[/quote]I meant “from the Operating System” stand point rather from lawer. System has no idea where the separate DLLs were compiled / dowloaded / linked. All these parts have to be consistent

[quote=“cstrato”]Windows users download and install the ROOT binary compiled with VC++ and the R binary compiled with MinGW. R allows developers to create “packages” which can contain
C/C++ source code, which is mostly compiled with MinGW, too.[/quote]It does not matter what user should do as soon as you current issue is concern. At the end of the day, your software “salad” has to be swallowed by the operating system as one single “dish”.[quote=“cstrato”]Since my package contains C++ source code dependent on ROOT I need to compile it with VC++, however R cannot find the ROOT libraries when compiling with /MD[/quote]I would be happy to help you further. To do that I need to understand what you mean :exclamation: speaking “R cannot find the ROOT libraries” :unamused:
The problem can be as simple as setting properly the PATH env variable.

[quote=“cstrato”] so I need to compile with /MT which works on WinXP.[/quote] :frowning: Did you miss my previous message ?

[quote=“cstrato”]However, it does not work on Vista therefore I am trying to compile ROOT also with option /MT with the thankful
help of Bertrand. I will se how far we get.[/quote]Well, it may help (for a while). However, one still needs to understand why :!: you need the “/MT” flag.
This is the MAIN question. See
ifh.de/CHEP97/main_pro.htm
ifh.de/CHEP97/abstract/g340.htm
"Dynamic libraries: maintaining a single source for Unix &Windows"

Otherwise, what you are doing is a guess job producing the ticking bomb.
Alas, I can not reproduce your problem to assist. Sorry. Hope Bertrand will be more lucky. Frankly, I do not understand how one can create the statically linked version of ROOT and still be able to load the custom DLLs properly. It sounds like a non-trivial project . . . to re-invent the Windows loader.

Dear Valeri,

1, That “R cannot find the root libraries” is only my interpretation of the error dialogbox which I get from Vista:
stat.ethz.ch/pipermail/r-devel/ … 54843.html
Maybe you have a different interpretation?

2, Since compiling my program with /MT DOES WORK WITOUT ANY PROBLEMS, since none of the WinXP users of my package
has reported any problem, I do NOT care if that it should not be done!!!

3, When I asked you if you mean that it is not possible to compile root with option /MT your answer was: "No, I did not say that."
Now you say that you “do not understand how one can create the statically linked version of ROOT…”.

Best regads
Christian

Dear Christian

[quote=“cstrato”]… 1, That “R cannot find the root libraries” is only my interpretation of the error dialogbox which I get from Vista:
stat.ethz.ch/pipermail/r-devel/ … 54843.html
Maybe you have a different interpretation?
[/quote]I’ve re-read the page one more time.
The first problem you reported there is about your “xps” DLL

[code]1. xps compiled on Vista with option “/MD”:
new R session:

library(xps,lib.loc=“C:/home/Rabbitus/CRAN/myRlib”)
Error in inDL(x, as.logical(local), as.logical(now), …) :
cannot load shared library ‘C:/home/CS/CRAN/myRlib/xps/libs/xps.dll’:
LoadLibrary failure: A DLL-Initialisationroutine failed.[/code]Forgive my French, but nothing suggests me it is about “R cannot find the root libraries” . From my standpoint is says, that "xps.dll is not compatible with the application that is attempting to load it in”.
Under XP you got more reasonable diagnostic in English[quote=“cstrato”]
Program: c:\Programme\R\R-2.9.0\bin\Rterm.exe
R6034
An application has made an attempt to load the C runtime library incorrectly.[/quote] This means the issue is not Vista specific. It is about “C runtime library” from Microsoft. It is not about ROOT DLL.

The dependency walker may show the reason of that message.[quote=“cstrato”]2, Since compiling my program with /MT DOES WORK WITOUT ANY PROBLEMS, since none of the WinXP users of my package
has reported any problem, I do NOT care if that it should not be done!!!
[/quote]If you do not care why you are raising this issue over and over again? It doesn’t help.
I’d agreed with your conclusion:

[quote=“cstrato”]Luckily, R runs w/o any problems [/quote][quote=“cstrato”]3, When I asked you if you mean that it is not possible to compile root with option /MT your answer was: “No, I did not say that.”
Now you say that you “do not understand how one can create the statically linked version of ROOT…”.[/quote]Hmm. :confused: That is strange citation; you cut out :open_mouth: the key point of the second statement.
Again, forgive my French,
[ul] 1) I did not see any contradiction :unamused: between first
" I did not say" and second “I do not understand”
2) Anyway,
2.1. My first clause was about vanilla ROOT (from CERN) rather about “R”. I have no idea about “R”.
2.2. My second (yes, stronger) clause was about capability of the good working statically linked ROOT (see 2.1 above) to load the third party DLL.[/ul] However, my understanding is that we are :exclamation: not dealing with ROOT at all. Your application is called :bulb: “R”. You do not start :bulb: any “root.exe” at all.

It does not matter whether it is possible or not to create root.exe with /MT flag. You are not going to use it are you? It does not matter what “2.1” clause says.

That means it is “R” that defines the run-time environment and this environment is not compatible with the ROOT DLLs. (Yes, on XP you are lucky, I know … There it is compatible )
To help you one needs first to know the way you build “R” then decide whether ROOT build can be adjusted to meet “R build” requirement.
I suspect it is “R” issue.
I am very sorry :frowning: . Since I cannot learn and build R :blush: , I cannot help you further :frowning: .
Hope my advices will help you eventually.

mingw.org/category/wiki/msvc

cran.r-project.org/doc/manuals/R … ws-toolset

[quote=“R”]…Only building with gcc 4.y.z is supported, and that compiler set works out-of-the-box on Windows Vista.
We have found that the build process for R is quite sensitive to the choice of tools: please follow our instructions exactly, even to the choice of particular versions of the tools. … [/quote]

mingw.org/wiki/FAQ

[quote=“minGW”]Why can’t I mix objects from different Compiler Brands or mix objects from different compiler versions of the same compiler brands?
This issue is not specific to MinGW: many compilers are mutually incompatible. [/quote]

Dear Valeri,

I see that you did a lot of searching for an answer, thank you.

However, you missed the relevant site “Using external compilers with R”:
stats.uwo.ca/faculty/murdoch … ilingDLLs/
and especially the document “Writing packages for R” which explains how to use VC++:
stats.uwo.ca/faculty/murdoch … ckages.txt
Please read the paragraph “Using Visual C++” which shows how to compile the DLL using /MT.

Some time ago I have already asked at the R-devel mailing list why it is not possible to use /MD, see:
stat.ethz.ch/pipermail/r-devel/ … 52830.html
stat.ethz.ch/pipermail/r-devel/ … 52927.html
stat.ethz.ch/pipermail/r-devel/ … 55200.html
As you can see (if you follow the threads) I have never received any helpful answer.

Best regads
Christian

Dear Christian,
I posted the helpful :wink: link only. Those clearly explain (from my stand point) what one should do to make “R” application working.
The link
stats.uwo.ca/faculty/murdoch … ckages.txt is useless since it does not show how one can create and load > 1 DLL. It does say how to create ONE.[quote=“cstrato”] … it is not possible to use /MD, see … [/quote]Well, if that is true it is a limitation of “R” and you can not use ROOT “as is” :cry:

[quote=“cstrato”] I have never received any helpful answer. [/quote]All you need is some R example that shows how one can create > 2 DLLs with VC++ where each DLL invokes some function defined by another DLL and performs some I/O operations. Ideally, one DLL opens some file and second one writes to that file and closes it. Both should print something to stdout/stderr. Can you do that with VC++ and no ROOT?

Dear Valeri,

Thank you, this is a good idea. Long time ago I have created an example w/o ROOT, which I will try to modify.

Best regads
Christian

Dear Valeri,

Meanwhile I have created a test package which contains only one simple C++ class and NO dependencies on any other library.
To compile this class from within R I have created the following Makefile.win:

CL            = "${MSVSPATH}/cl"
LINK          = "${MSVSPATH}/link"

MYHDR  = MyClassA.h rwrapper.h 
MYSRC  = MyClassA.cxx rwrapper.cxx
MYOBJ  = MyClassA.obj rwrapper.obj 

MyClass.dll:  $(MYOBJ)
	$(LINK) /dll /def:MyClass.def /out:MyClass.dll fp10.obj *.obj 
	
MyClassA.obj: MyClassA.h MyClassA.cxx
	$(CL) /MT /EHsc /Ox /D "MSVC" /D "WIN32" /c MyClassA.cxx
#	$(CL) /MD /D_STATIC_CPPLIB /EHsc /Ox /D "MSVC" /D "WIN32" /c MyClassA.cxx

rwrapper.obj: rwrapper.h rwrapper.cxx
	$(CL) /MT /EHsc /Ox /D "MSVC" /D "WIN32" /c rwrapper.cxx
#	$(CL) /MD /D_STATIC_CPPLIB /EHsc /Ox /D "MSVC" /D "WIN32" /c rwrapper.cxx

clean:
	rm -f $(MYOBJ) *.a *.d *.rc 

When I use option /MT everything is ok, but when I use option /MD I get the following dialogbox on Windows XP:

     Microsoft Visual C++ Runtime Library
     Runtime Error!

     Program:C:\Programme\R\R-2.9.0\bin\Rterm.exe
     R6034

     An application has made an attempt to load the C runtime library incorrectly.
     Please contact the application's support team for more information.

As you see, R is not able to load the correct CRT. Adding /D_STATIC_CPPLIB did not help either although it should
load the static library, at least as far as I understand: msdn.microsoft.com/en-us/library/2kzt1wy3.aspx

Do you have any idea how to change the Makefile to force the use of the static CRT?

Best regads
Christian

[quote=“cstrato”]… Meanwhile I have created a test package which contains only one simple C++ class and NO dependencies on any other library.
To compile this class from within R I have created the following Makefile.win: ....When I use option /MT everything is ok, but when I use option /MD I get the following dialogbox on Windows XP: Program:C:\Programme\R\R-2.9.0\bin\Rterm.exe R6034 An application has made an attempt to load the C runtime library incorrectly. Please contact the application's support team for more information. As you see, R is not able to load the correct CRT. [/quote]
I am not sure your conclusion is correct. Very likely the Rterm.exe loads some correct CRT at startup time. That “CRT” is not compatible with the DLL you linked your custom DLL with. [quote=“cstrato”]… Do you have any idea how to change the Makefile to force the use of the static CRT?[/quote]One can not answer your question unless one knows how C:\Programme\R\R-2.9.0\bin\Rterm.exe was built. This means R forum is the right place to ask.

The “Rterm.exe” has to be linked and loaded with some C/C++ DLL run-time library and you have to build and link yours against of that DLL too.
I did advise you to use the “Dependency Walker” to reveal that information. Apparenty, " R " people are well aware what library they link Rterm.exe against of. They do not need to spend time investigating the issue with "Dependency Walker"
Again, ROOT forum is not right place. I do not see any ROOT / Visual C / C / C++ issue here yet.

The advice was given. That is ALL parts of

"your application" ="Rterm.exe + your custom DLL"have to be consistent. There is no magic wand, sorry :cry:
The Microsoft message:Please contact the application's support team for more informationis correct too. My guess “The support team” is “R” team.