Programs Only Run on My Machine!

This is a discussion on Programs Only Run on My Machine! within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I programmed a basic SSH client program (similar in concept to PuTTY) and I'm having troubles running it on ...

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230

    Programs Only Run on My Machine!

    Hello, I programmed a basic SSH client program (similar in concept to PuTTY) and I'm having troubles running it on any computer other than my own. I'm using Windows XP and Visual C++ 2008 Express Edition as my compiler.

    Basically I'm using an SSH library called "libssh2". I compiled the libSSH library into a .lib file called libssh2.lib, and included it in my project under Project Properties > Linker > Input > Additional Dependencies. I also have a few others there. This is what my Additional Dependencies looks like:

    libssh2.lib ws2_32.lib shlwapi.lib

    My include headers are:

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <Winsock2.h>
    #include <Ws2tcpip.h>
    #include <libssh2.h>
    #include <Shlwapi.h>
    #include <string>
    #include <fstream>
    #include <vector>
    #include <cmath>
    #include <ctime>
    The error message I get when I run this on a computer that it doesn't work on is:

    The system cannot execute the specified program.

    I'm pretty sure this is because I'm missing "C++ Runtime" files or something... But, I have no idea what those files are, I'm not sure how to obtain them, and I really don't want to have to have a heap of files in my programs folder.

    Is there a way to compile whatever it is that's missing into my program? How do I fix this!

    Thanks
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Are you including the libssh2.dll file with your application executable? Also, make sure you compile your code in release mode instead of debug mode. Chances are the other machine does not have the debug runtime libraries.

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Quote Originally Posted by bithub View Post
    Are you including the libssh2.dll file with your application executable? Also, make sure you compile your code in release mode instead of debug mode. Chances are the other machine does not have the debug runtime libraries.
    Yeah I'm compiling in release mode. I'm not including the DLL though, I never compiled one. Do I need to do that and include it?
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  4. #4
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Oh, another thing, I sent it to my friend and he doesn't have the libssh2 files but he was able to run it :/ He has Visual C++ installed though.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Anytime you link to a .lib file, you also need a corresponding DLL file. Now the DLLs for ws2_32.lib and shlwapi.lib come with Windows, so you don't need to worry about that. When you compiled libssh2, it generated 2 files: libssh2.lib and libssh2.dll. You need to include libssh2.dll when you distribute your application.

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,251
    Quote Originally Posted by bithub View Post
    Anytime you link to a .lib file, you also need a corresponding DLL file. Now the DLLs for ws2_32.lib and shlwapi.lib come with Windows, so you don't need to worry about that. When you compiled libssh2, it generated 2 files: libssh2.lib and libssh2.dll. You need to include libssh2.dll when you distribute your application.
    You're assuming libssh2 was compiled as a DLL. It could just be a static library. The fact that at least one person (somebody who has VC++ installed) is able to run it suggests to me that the files which are missing are the C++ runtime msvcprt.dll.

    To really check, open a Visual Studio command prompt and run "depends foo.exe" on your program to see the DLLs it actually requires.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    This is me running depends on my file on the computer that it actually works on: http://img294.imageshack.us/img294/3206/asdfx.jpg

    So does this mean I need to include ALL those DLL's in the left view as well as the DLL's in the submenus of those DLL's? And why does msvcrx90.dll have a yellow ?, because it still runs. And those msvcrx90.dll's are on my computer, I found them with search in some directory.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,251
    The yellow circles indicate libraries which depends could not find. It works when you run it from Visual Studio (or the VS command prompt) because VS adds the path to those DLLs to the DLL search path.

    These are exactly the DLL files you need to distribute in order for the program to function elsewhere. The other DLLs, if you notice, all come from system32, and should be present everywhere.

    EDIT: You should try copying those files to your build area (where the .exe is) and run depends again. The yellow circles should go away, and you will get some additional information. Since depends could not locate those DLLs, it was unable to resolve any dependencies they might have, so there may in fact be MORE DLLs you need to include.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Reading this article will give you more information on how to distribute the runtime files.

  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    If you have the Express edition you will need to find a third party install program that can analyze the dependencies of your code and include them in the install binary data.

    All versions of MSVS save for Express have the Setup and Deployment Wizard which will create executables and MSI's that will correctly install your application for use on another computer. It can auto-register DLL's for use on another machine and it will allow you to specify if you want to place an icon on the user's desktop. It will also allow you to specify how your program looks on their programs menu, how the application folder is laid out, what registry entries you wish to create for the program, etc., etc.

  11. #11
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Ok uh, so I installed the Redistribution Package: Download details: Visual C++ 2008 Redistributable Package (x86)

    Even know the C++ Runtime files are located on the machine, it still cannot run my program... I checked with depends.exe and nothing else appears to be missing (like libssh2.dll, it doesn't mention that or anything because the libssh2.lib is compiled into the program I'm guessing).

    I'm using Express by the way So what else could this be? I thought installation the redistribution package would fix everything...
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  12. #12
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    If you've got SP1 installed for Visual Studio, you'll need the SP1 version of the redistributable. Since you're linked to the CLR as well, the computer will have to have the relevant version of the .Net framework installed as well.

    If the manifest isn't embedded either (Project Properties->Linker->Manifest->Embed Manifest, that's from memory so it might be slightly different), you'll need to have that as well when you run the exe.

  13. #13
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Have you registered the DLLs with regsvr32? If the DLLs are not registered on the system and came from another system then they will be unavailable for use. Also you can right click and check the properties of the executable. Often times an exe will be flagged as blocked and you will have to manually unblock it in order for it to work.

  14. #14
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,251
    Quote Originally Posted by Bubba View Post
    Have you registered the DLLs with regsvr32? If the DLLs are not registered on the system and came from another system then they will be unavailable for use. Also you can right click and check the properties of the executable. Often times an exe will be flagged as blocked and you will have to manually unblock it in order for it to work.
    I've never heard of this requirement that DLLs must be registered.

    Given that regsvr32 does what it does by... loading the DLL... then calling DllRegisterServer, it is clearly not required that a DLL must be registered in order to be used.

    (Obviously, DLLs which provide COM objects need to be registered, and certain other things require registration, but there should be nothing preventing a DLL from being loaded especially if it's in the same directory as the executable image)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #15
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Ok... It turns out the problem is with sshlib2.lib... So, how on earth is this possible.

    #1 The library is statically linked (correct terminology?) therefore it's compiled into the program.
    #2 It runs on my machine without anything in the same directory as it.
    #3 It runs on my friends machine without sshlib2 as well (he's the one with Visual C++ 2008 and the SDK(s) and whatever installed).

    Another thing, with sshlib2 I have the option of compiling it into a DLL or a lib. I chose lib and statically linked it (I followed a guide). Should I maybe use the DLL instead and somehow link this in my program instead of the .LIB? And how would I go about this if it's a valid solution?

    Also, if that IS a valid solution, why on earth does my program run on my friends computer when it's statically linked...

    Gah this is so frustrating and confusing :/ Thanks guys.
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How come Dev C++ cant run some programs??
    By Sephiroth in forum C Programming
    Replies: 41
    Last Post: 09-17-2005, 05:35 AM
  2. School Mini-Project on C/C++ (Need Your Help)..
    By EazTerence in forum C++ Programming
    Replies: 4
    Last Post: 09-08-2005, 01:08 AM
  3. Creating a Virtual Machine
    By Chronom1 in forum C++ Programming
    Replies: 7
    Last Post: 10-05-2003, 11:11 AM
  4. how do i run external programs from source?
    By tameritoke in forum C++ Programming
    Replies: 1
    Last Post: 05-23-2003, 02:44 PM
  5. how to compile & run c programs in unix?
    By Unregistere in forum C Programming
    Replies: 2
    Last Post: 10-09-2002, 10:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21