CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old August 31st, 2003, 10:33 PM
    CBasicNet CBasicNet is offline
    Member +
     
    Join Date: Sep 2002
    Location: Singapore
    Posts: 664
    CBasicNet has a spectacular aura about (150+)CBasicNet has a spectacular aura about (150+)
    Unhappy Cannot static linkage with CxImage

    Hi guys,

    I have made a "picture to ASCII" converter. I have a problem here; I cannot "Use MFC in a static Library", I can only link dynamically. I need to link statically as I want to distribute my program to my friends. To know more, please click on the link in my signature.

    I use the CxImage from
    here

    These are the linkage errors and warnings I have,

    AsciiArt error LNK2005: _fclose already defined in libcmt.lib(fclose.obj)
    AsciiArt error LNK2005: _fread already defined in libcmt.lib(fread.obj)
    AsciiArt error LNK2005: _fwrite already defined in libcmt.lib(fwrite.obj)
    AsciiArt error LNK2005: _fseek already defined in libcmt.lib(fseek.obj)
    AsciiArt error LNK2005: _ftell already defined in libcmt.lib(ftell.obj)
    AsciiArt error LNK2005: _fflush already defined in libcmt.lib(fflush.obj)
    AsciiArt error LNK2005: _free already defined in libcmt.lib(free.obj)
    AsciiArt error LNK2005: _malloc already defined in libcmt.lib(malloc.obj)
    AsciiArt error LNK2005: _realloc already defined in libcmt.lib(realloc.obj)
    AsciiArt error LNK2005: _strncpy already defined in libcmt.lib(strncpy.obj)
    AsciiArt error LNK2005: _calloc already defined in libcmt.lib(calloc.obj)
    AsciiArt error LNK2005: _sprintf already defined in libcmt.lib(sprintf.obj)
    AsciiArt error LNK2005: _strncmp already defined in libcmt.lib(strncmp.obj)
    AsciiArt error LNK2005: _isprint already defined in libcmt.lib(_ctype.obj)
    AsciiArt error LNK2005: _memmove already defined in libcmt.lib(memmove.obj)
    AsciiArt error LNK2005: _abort already defined in libcmt.lib(abort.obj)
    .....
    AsciiArt warning LNK4006: _fclose already defined in libc.lib(fclose.obj); second definition ignored
    AsciiArt warning LNK4006: _fread already defined in libc.lib(fread.obj); second definition ignored
    AsciiArt warning LNK4006: _fwrite already defined in libc.lib(fwrite.obj); second definition ignored
    AsciiArt warning LNK4006: _fseek already defined in libc.lib(fseek.obj); second definition ignored
    AsciiArt warning LNK4006: _ftell already defined in libc.lib(ftell.obj); second definition ignored
    AsciiArt warning LNK4006: _fflush already defined in libc.lib(fflush.obj); second definition ignored
    AsciiArt warning LNK4006: _free already defined in libc.lib(free.obj); second definition ignored
    AsciiArt warning LNK4006: _malloc already defined in libc.lib(malloc.obj); second definition ignored
    AsciiArt warning LNK4006: _realloc already defined in libc.lib(realloc.obj); second definition ignored
    AsciiArt warning LNK4006: _strncpy already defined in libc.lib(strncpy.obj); second definition ignored
    AsciiArt warning LNK4006: _calloc already defined in libc.lib(calloc.obj); second definition ignored
    AsciiArt warning LNK4006: _sprintf already defined in libc.lib(sprintf.obj); second definition ignored
    AsciiArt warning LNK4006: _isprint already defined in libc.lib(_ctype.obj); second definition ignored
    AsciiArt warning LNK4006: _memmove already defined in libc.lib(memmove.obj); second definition ignored
    AsciiArt warning LNK4006: _abort already defined in libc.lib(abort.obj); second definition ignored
    ........
    There are more but I think they are the same. I tried to set the libraries from Multithreaded to Single threaded, I still get the same errors.

    However, when I linked dynamically, eveything went smoothly.
    __________________
    Please kindly rate me if you find my postings useful.
    Reply With Quote
      #2    
    Old August 31st, 2003, 10:48 PM
    CBasicNet CBasicNet is offline
    Member +
     
    Join Date: Sep 2002
    Location: Singapore
    Posts: 664
    CBasicNet has a spectacular aura about (150+)CBasicNet has a spectacular aura about (150+)
    To explain further, I use the static libs of CxImage when I link statically or dynamically. I'm very sure they are static libs, not import lib, as I used dependency walker to check if it uses any non-standard DLLs.

    Any help would be appreciated.

    Thank you.
    __________________
    Please kindly rate me if you find my postings useful.
    Reply With Quote
      #3    
    Old August 31st, 2003, 11:01 PM
    Runt888 Runt888 is offline
    Member +
     
    Join Date: Jun 2002
    Location: Colorado, U.S.A.
    Posts: 971
    Runt888 has a spectacular aura about (125+)Runt888 has a spectacular aura about (125+)
    I've used CxImage before. The projects that you can download have a few problems with them. First you should make sure all of them are set to use the single threaded or multithreaded libraries, not a mixture of both. Then compile the CxImage project, not CxImageCrtDll or CxImageMfcDll. This will create a library that you can link to statically. Let me know if you get it to work. I can email you the libraries if you need them.

    Kelly
    Reply With Quote
      #4    
    Old August 31st, 2003, 11:19 PM
    CBasicNet CBasicNet is offline
    Member +
     
    Join Date: Sep 2002
    Location: Singapore
    Posts: 664
    CBasicNet has a spectacular aura about (150+)CBasicNet has a spectacular aura about (150+)
    Hi Kelly,

    The situation is this I can link with the static libs of CxImage but it is dynamically linkage to MFC.(Strange, isn't it?) I found this out when I changed from static linkage to dynamic linkage, everything suddenly builds just fine. That means my program uses hybrid of static libs(CxImage) and DLLs of MFC.
    __________________
    Please kindly rate me if you find my postings useful.
    Reply With Quote
      #5    
    Old August 31st, 2003, 11:24 PM
    Runt888 Runt888 is offline
    Member +
     
    Join Date: Jun 2002
    Location: Colorado, U.S.A.
    Posts: 971
    Runt888 has a spectacular aura about (125+)Runt888 has a spectacular aura about (125+)
    I had a lot of similar problems when using CxImage. I set the compiler to ignore the libraries that had the conflicts, and that allowed it to compile. However, when I changed the libraries to use the same version of the C runtime libraries, it solved all of my problems. I don't use MFC, so if it really is a problem with that, I don't know what to tell you.

    Kelly
    Reply With Quote
      #6    
    Old August 31st, 2003, 11:28 PM
    CBasicNet CBasicNet is offline
    Member +
     
    Join Date: Sep 2002
    Location: Singapore
    Posts: 664
    CBasicNet has a spectacular aura about (150+)CBasicNet has a spectacular aura about (150+)
    I can rewrite in Win32 if I'm desperate. But the errors are about (as you can see in the first post) C functions. And can you tell me how to set in VC to use the same version of the C runtime libraries?
    __________________
    Please kindly rate me if you find my postings useful.
    Reply With Quote
      #7    
    Old September 1st, 2003, 12:01 AM
    Runt888 Runt888 is offline
    Member +
     
    Join Date: Jun 2002
    Location: Colorado, U.S.A.
    Posts: 971
    Runt888 has a spectacular aura about (125+)Runt888 has a spectacular aura about (125+)
    Sure, it's pretty easy. Open the CxImage workspace with all the libraries. Select Project->Properties. Select each project in the list and make sure they all have the same settings for the MFC library (Not Using MFC for a static library). Then select the C/C++ tab and select Code Generation in the combo box. In the Use Run-time Library combo box, make sure all of them are set to Single-Threaded (or multi threaded depending on your settings). Then remake all the libraries and try to recompile your project. Hope it works.

    Kelly
    Reply With Quote
      #8    
    Old September 1st, 2003, 04:35 AM
    CBasicNet CBasicNet is offline
    Member +
     
    Join Date: Sep 2002
    Location: Singapore
    Posts: 664
    CBasicNet has a spectacular aura about (150+)CBasicNet has a spectacular aura about (150+)
    Thanks Kelly. It works! Thanks again!

    It turns out that CxImage static lib projects, in my case, are not set uniformly the same; some uses MFC shared library while some uses MFC static library.

    __________________
    Please kindly rate me if you find my postings useful.
    Reply With Quote
      #9    
    Old September 1st, 2003, 02:02 PM
    Runt888 Runt888 is offline
    Member +
     
    Join Date: Jun 2002
    Location: Colorado, U.S.A.
    Posts: 971
    Runt888 has a spectacular aura about (125+)Runt888 has a spectacular aura about (125+)
    Glad to hear it. I spent way too much time debugging that same problem. Probably easier than writing my own image library though.

    Kelly
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:10 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009