views:

248

answers:

4
#include <gtk/gtk.h>

int main( int argc, char *argv[] )
{
    GtkWidget *window;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_show  (window);

    gtk_main ();

    return 0;
}

I tried putting various versions of MSVCR80.dll under the same directory as the generated executable(via cmake),but none matched.

Is there a general solution for this kinda problem?

UPDATE

Some answers recommend install the VS redist,but I'm not sure whether or not it will affect my installed Visual Studio 9, can someone confirm?

Manifest file of the executable

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>

It seems the manifest file says it should use the MSVCR90, why it always reporting missing MSVCR80.dll?

FOUND

After spending several hours on it,finally I found it's caused by this setting in PATH:

D:\MATLAB\R2007b\bin\win32

After removing it all works fine.But why can that setting affect my running executable from using msvcr90 to msvcr80 ???

A: 

1.

Maybe, CMake uses external compiler. In your case - it seems to be Microsoft Visual C++ 2005. And target executable is linked with C++ runtime dinamycally what means that Microsoft Visual C++ 2005 SP1 Redistributable Package (x86) packages must be installed on every computer running the program.

MSVCR = MicroSoft Visual C++ Runtime

See also this MSDN article: /MD, /MT, /LD (Use Run-Time Library)

2.

To indicate CMake use GCC: How do I use a different compiler?

3.

Try use Dependency Walker to figure out how exactly dependency are being exists

abatishchev
No,it's generated with `cmake -G"NMake Makefiles" ..` and it seems correct to me. Is it possible to tell cmake to switch to `MSVCR90.dll` ?
Gtker
It's using `nmake` as compiler and that's what I want, except that it uses `MSVCR80.dll`, my installed `cmake` ships with itself `MSVCR90.dll`, so how can I let it switch accordingly ?
Gtker
@Runner: Miss you idea a bit. What exactly uses nmake? NMake is a make application for Microsoft VC++ compiler, like GNU Make is for GNU C/C++ compilers, and CMake is an universal one.
abatishchev
I first generated the makefile for `nmake` via `cmake -G"NMake Makefiles" ..`, then used `nmake` to generate the executable which reports lack of MSVCR80.dll.
Gtker
As far as I could understand from ~buratinas's answer cmake doesn't mean in this sutuation, probably you have to configure gtk environment?
abatishchev
I've already included required libraries and header files manually to make the link work...But can't be executed...
Gtker
Will it affect my installed Visual Studio 9 if I install the redist package?
Gtker
@Runner: Each VC++ compiler is targets runtime and each VS targeted to appropriate compiler. So both VS5005/2008/2010 and VCRT 8/9/10 can be installed simultaneously
abatishchev
But I've already tried various versions of MSVCR80.dll under `C:\WINDOWS\WinSxS` but none of them matched. Are you sure the VS redist will help?
Gtker
@Runner: I assure you that there are nothing bad in installing VS runtime of any version supported SxS (i.e. 2005 and above)
abatishchev
Yep, no bad. But it still doesn't solve the problem after installation.
Gtker
@Runner: Please try a method a described in paragraph 3 of my post
abatishchev
@abatishchev, I've found the root cause by luck, but the reason remains to be clarified!Why can a setting in `PATH` affect the used version of `MSVCR.dll`?
Gtker
@Runner: Every Windows resolves dependencies in compliance with it's configuration. All Windows searches executable's root directory first and after that - in another places. SxS supported Windows searches their. If fails - in `PATH` environment variable, in `App Paths` registry key, etc. You can try to use `%PATH%`
abatishchev
But the manifest file says clearly it should use a msvcr90.dll,but for the sake of the `PATH` environment variable, it switches to msvcr80.dll,which lead to my trouble so far. But how does `PATH` affect this remains unclear.
Gtker
@Runner: If manifest exists and version 9.0 is specified there obligatory, maybe that means that some another modules has no manifest and/or has broken dependency settings..
abatishchev
How can I force my executable to use a specific MSVCR.dll regardless of how `PATH` is set?
Gtker
@Runner: Put appropriate file in the root directory. Anyway Windows searches there first before any
abatishchev
It doesn't work,as stated at the very beginning of my post behind the code pasted.
Gtker
@Runner: Are you sure that exactly your application can't find MSVCR? Maybe you have to put it into the root directory of one of your application dependency?
abatishchev
+1  A: 

Answering the topic question, even gtk application needs Microsoft libraries because it doesn't try to emulate look and behavior of Windows widgets. Instead, gtk uses native APIs to draw widgets. Even if you compile with MinGW compiler your program would still need MSVCR.

Try to look into makefiles to get an idea, why doesn't cmake link properly.

buratinas
Is it possible to tell cmake to switch to `MSVCR90.dll` ?
Gtker
A: 

May I suggest that you read this page? http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F

In short, you need to change your CMake file to link statically to the MSVC runtime.

(By the way, this has nothing to do with Gtk; every program will be linked against the MSVC runtime by default)

Krumelur
A: 

You need the VS redist for it to run. Just placing a DLL in the folder will not work, since the loader looks at the manifest for dependencies to satisfy, which must reside in a particular place in the WinSxS directory.

It's not a linker problem, you just can't run the EXE you generated.

Alex
It's still the same after installing the VS redist.
Gtker