views:

572

answers:

1

(Why I am trying to do this: I have had no luck in using the pre-built binaries for libpng on Windows (despite many hours of trial and error), and therefore am now trying to compile it myself. I found this helpful blog post concerning this, complete with a Microsoft Visual Studio 2008 project file, but unfortunately have still not been able to use it.)

It successfully compiles when linking to the zlib binary found here, but when attempting to link it to a test file I receive the following:

    C:\Documents and Settings\Administrator\My Documents>cl "C:\Documents and Settin
    gs\Administrator\My Documents\test.c" "C:\Documents and Settings\Administrator\M
    y Documents\libpng.lib" -I "C:\Documents and Settings\Administrator\My Documents\include"

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.

    test.c
    Microsoft (R) Incremental Linker Version 9.00.30729.01
    Copyright (C) Microsoft Corporation.  All rights reserved.

    /out:test.exe
    test.obj
    "C:\Documents and Settings\Administrator\My Documents\libpng.lib"
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _abort already defined in LIBCMT.lib(
    abort.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fread already defined in LIBCMT.lib(
    fread.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib
    (malloc.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _free already defined in LIBCMT.lib(f
    ree.obj)
    MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: ___iob_func already defined in LIBCMT
    .lib(_file.obj)
    LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; u
    se /NODEFAULTLIB:library
    test.exe : fatal error LNK1169: one or more multiply defined symbols found

Could anyone care to shed some light as to how to fix these errors?

+3  A: 

The problem is that one of the two projects is using Multi-threaded DLL while the other is using Multi-threaded (without DLL in it) in Project Properties -> Configuration Properties -> C/C++ -> Code generation.

Happened to me several times.

Make sure to "synchronize" that setting even for release builds, and for each possible combination (debug, non debug, etc)

Andreas Bonini
Thank you! Hours of a headache solved in 10 minutes :)
Sam
XD thanks :D [...at least 15 chars]
Andreas Bonini