CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2008
    Posts
    29

    exe will not run without dll.

    I have a MySQL based exe and it needs libmySQL.dll to run.

    I have looked and looked on how to "merge", and I believe I found out that you can't do that with .NET. Though maybe that's not why.

    So if that's not possible is there any way to compile the dll into the exe and it gets extracted once opened the exe is opened?

    Any other ideas are appreciated too.

    Thanks.

  2. #2
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: exe will not run without dll.

    Do you need specific functions from the DLL and don't want to deal with imports and/or function pointers? If thats the case MySQL comes with the static library version, and you can just include that to your linker settings and it gets compiled in to the project. Otherwise you just need to put the DLL where the application can see it. Just put it in the same directory of the EXE.
    Compiling DLLs into the EXE really defeats the point of DLLs.
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

  3. #3
    Join Date
    Oct 2008
    Posts
    29

    Re: exe will not run without dll.

    I would love to use a static library, but I can't seem to find one at Mysql.com
    There forums are pretty much dead where I would get help on this.

    I think I saw that mysqlclient.lib was a static lib that would remove the need for the dll.
    I tried compiling with it, but I still needed the dll. :\

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: exe will not run without dll.

    Quote Originally Posted by Clipster
    <snip>and I believe I found out that you can't do that with .NET. </snip>
    1) Why would .NET matter....This is the C++ forum....
    2) You assumption is untrue. You can create Net Modules.....
    3) As pointed out static linking avoids the need for the DLL..but has its own set of disatvantages...WHY dont you want to user the DLL????
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Dec 2003
    Location
    Syracuse, NY
    Posts
    400

    Re: exe will not run without dll.

    What are you actually trying to do? Did you put the DLL in the directory of the EXE?

    The static library is located on my MySQL installation at <MySQL Root Directory>\lib\opt
    "Windows programming is like going to the dentist: You know it's good for you, but no one likes doing it."
    - Andre LaMothe

    DLL For Beginners(UPDATED)
    Please use CODE tags
    Rate me if I've helped.

  6. #6
    Join Date
    Oct 2008
    Posts
    29

    Re: exe will not run without dll.

    Thats what I'm linking to.

    If I link to libmysql.lib and wsock32.lib I can compile. But I need DLL to run.

    Here it shows that libmysql.lib is a wrapper to load the dll.
    http://dev.mysql.com/doc/refman/5.1/...compiling.html
    And it says or you can use mysqlclient.lib.

    If I don't link to libmysql.lib I get unresolved externals link errors.
    So I've been linking to libmysql.lib, wsock32.lib and mysqlclient.lib. Though linking to mysqlclient has been kind of pointless as it compiles with out it and with same results.

    I'm compiling With Visual Studio 2008.

    Could mysqlclient.lib not be working right?
    I know when I link to it with Dev c++ mingw crashes.. xD

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: exe will not run without dll.

    Quote Originally Posted by Clipster
    Here it shows that libmysql.lib is a wrapper to load the dll.
    http://dev.mysql.com/doc/refman/5.1/...compiling.html
    And it says or you can use mysqlclient.lib.
    One little word.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #8
    Join Date
    Oct 2008
    Posts
    29

    Re: exe will not run without dll.

    I said if don't link to libmysql.lib I get unresolved externals link errors....

  9. #9
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: exe will not run without dll.

    If you use the appropriate headers for the static library, and link with the static library, then you should not get any errors.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  10. #10
    Join Date
    Oct 2008
    Posts
    29

    Re: exe will not run without dll.

    All right, Ill try messing with it and see what I get. Ill reply back on where I'm at then.

    Thanks.

  11. #11
    Join Date
    Oct 2008
    Posts
    29

    Re: exe will not run without dll.

    No luck.... This is what I'm getting when I don't link to libmysql.lib and link to mysqlclient.lib:

    Code:
    1>Generating Code...
    1>Linking...
    1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(fflush.obj) : error LNK2005: _fflush already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(dosmap.obj) : error LNK2005: __errno already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(setlocal.obj) : error LNK2005: _setlocale already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(sprintf.obj) : error LNK2005: _sprintf already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRTD.lib(cinitexe.obj)
    1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRTD.lib(cinitexe.obj)
    1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRTD.lib(cinitexe.obj)
    1>LIBCMTD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRTD.lib(cinitexe.obj)
    1>LIBCMTD.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(winsig.obj) : error LNK2005: _signal already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj)
    1>LIBCMTD.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(tzset.obj) : error LNK2005: __tzset already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(vsprintf.obj) : error LNK2005: _vsprintf already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(vsnprnc.obj) : error LNK2005: _vsprintf_s already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(_ctype.obj) : error LNK2005: _isspace already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(_ctype.obj) : error LNK2005: _iscntrl already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(atox.obj) : error LNK2005: _atoi already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(getenv.obj) : error LNK2005: _getenv already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(dbgrptw.obj) : error LNK2005: __CrtDbgReportW already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(printf.obj) : error LNK2005: _printf already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(strtol.obj) : error LNK2005: _strtol already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LIBCMTD.lib(strtol.obj) : error LNK2005: _strtoul already defined in MSVCRTD.lib(MSVCR90D.dll)
    1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>mysqlclient.lib(libmysql.obj) : error LNK2019: unresolved external symbol _ntohs@4 referenced in function _mysql_server_init@12
    1>mysqlclient.lib(viosocket.obj) : error LNK2001: unresolved external symbol _ntohs@4
    1>mysqlclient.lib(libmysql.obj) : error LNK2019: unresolved external symbol _getservbyname@8 referenced in function _mysql_server_init@12
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _connect@12 referenced in function _my_connect
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _WSAGetLastError@0 referenced in function _cli_advanced_command
    1>mysqlclient.lib(viosocket.obj) : error LNK2001: unresolved external symbol _WSAGetLastError@0
    1>mysqlclient.lib(my_gethostbyname.obj) : error LNK2001: unresolved external symbol _WSAGetLastError@0
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _htons@4 referenced in function _mysql_real_connect@32
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _inet_addr@4 referenced in function _mysql_real_connect@32
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _socket@12 referenced in function _mysql_real_connect@32
    1>mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function _my_end
    1>mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _win32_init_tcp_ip
    1>mysqlclient.lib(vio.obj) : error LNK2019: unresolved external symbol _ioctlsocket@12 referenced in function _vio_new
    1>mysqlclient.lib(viosocket.obj) : error LNK2001: unresolved external symbol _ioctlsocket@12
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _recv@16 referenced in function _vio_read
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _send@16 referenced in function _vio_write
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _setsockopt@20 referenced in function _vio_fastsend
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _closesocket@4 referenced in function _vio_close
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _shutdown@8 referenced in function _vio_close
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _getpeername@12 referenced in function _vio_peer_addr
    1>mysqlclient.lib(my_gethostbyname.obj) : error LNK2019: unresolved external symbol _gethostbyname@4 referenced in function _my_gethostbyname_r
    1>mysqlclient.lib(my_net.obj) : error LNK2019: unresolved external symbol _inet_ntoa@4 referenced in function _my_inet_ntoa
    1>C:\Users\Sam\Documents\Visual Studio 2008\Projects\keyrecoding\Debug\keyrecoding.exe : fatal error LNK1120: 18 unresolved externals
    1>Build log was saved at "file://c:\x\x\x\Visual Studio 2008\Projects\x\x\Debug\BuildLog.htm"
    1>x - 61 error(s), 5 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    If I ignore the libcmt.lib library then I get:
    Code:
    1>Linking...
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _connect@12 referenced in function _my_connect
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol __iob referenced in function _mysql_read_default_options
    1>mysqlclient.lib(default.obj) : error LNK2001: unresolved external symbol __iob
    1>mysqlclient.lib(my_thr_init.obj) : error LNK2001: unresolved external symbol __iob
    1>mysqlclient.lib(my_messnc.obj) : error LNK2001: unresolved external symbol __iob
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _htons@4 referenced in function _mysql_real_connect@32
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _inet_addr@4 referenced in function _mysql_real_connect@32
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _WSAGetLastError@0 referenced in function _mysql_real_connect@32
    1>mysqlclient.lib(viosocket.obj) : error LNK2001: unresolved external symbol _WSAGetLastError@0
    1>mysqlclient.lib(my_gethostbyname.obj) : error LNK2001: unresolved external symbol _WSAGetLastError@0
    1>mysqlclient.lib(client.obj) : error LNK2019: unresolved external symbol _socket@12 referenced in function _mysql_real_connect@32
    1>mysqlclient.lib(libmysql.obj) : error LNK2019: unresolved external symbol _ntohs@4 referenced in function _mysql_server_init@12
    1>mysqlclient.lib(viosocket.obj) : error LNK2001: unresolved external symbol _ntohs@4
    1>mysqlclient.lib(libmysql.obj) : error LNK2019: unresolved external symbol _getservbyname@8 referenced in function _mysql_server_init@12
    1>mysqlclient.lib(vio.obj) : error LNK2019: unresolved external symbol _ioctlsocket@12 referenced in function _vio_new
    1>mysqlclient.lib(viosocket.obj) : error LNK2001: unresolved external symbol _ioctlsocket@12
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _recv@16 referenced in function _vio_read
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _send@16 referenced in function _vio_write
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _setsockopt@20 referenced in function _vio_fastsend
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _closesocket@4 referenced in function _vio_close
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _shutdown@8 referenced in function _vio_close
    1>mysqlclient.lib(viosocket.obj) : error LNK2019: unresolved external symbol _getpeername@12 referenced in function _vio_peer_addr
    1>mysqlclient.lib(my_gethostbyname.obj) : error LNK2019: unresolved external symbol _gethostbyname@4 referenced in function _my_gethostbyname_r
    1>mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function _my_end
    1>mysqlclient.lib(my_init.obj) : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _win32_init_tcp_ip
    1>mysqlclient.lib(my_net.obj) : error LNK2019: unresolved external symbol _inet_ntoa@4 referenced in function _my_inet_ntoa
    1>C:\Users\Sam\Documents\Visual Studio 2008\Projects\mysqlclient\Debug\mysqlclient.exe : fatal error LNK1120: 19 unresolved externals
    1>Build log was saved at "file://c:\x\x\x\Visual Studio 2008\Projects\x\x\Debug\BuildLog.htm"
    1>x - 27 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    EDIT:

    GOT IT!!!!!!!!!!!!!!!!!!!

    I changed Code Gen to Multi-threaded Debug (/MTd)
    And included the debug libs for debug/opt libs for release.

    The library's that are now included are, mysqlclient.lib, mysys.lib and wsock32.lib.

    I can't believe it took me a week to get this right!
    Last edited by Clipster; November 3rd, 2008 at 10:09 PM.

  12. #12
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: exe will not run without dll.

    Remember that Code Gen setting. You'll encounter that with some regularity. I do.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured