LNK4042 object specified more than once; extras ignored

Gavin Williams 761 Reputation points
2021-06-05T07:44:19.493+00:00

Hi,

I need to get rid of this warning, how can I work out what object is specified more than once, and where, why is it happening?

The linker warning file is Application.obj

Developer technologies | C++
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2021-06-11T15:07:06.187+00:00

    Try changing Item Type (in Project Properties dialog) of all .h files to “C/C++ header” (instead of “C/C++ compiler”).

    4 people found this answer helpful.

  2. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    2021-06-07T02:51:56.597+00:00

    Hi,

    LNK4042 essentially means your linker command line has two or more .obj files that have the same name. The warning tells you that only the first one gets linked. As far as I'm concerned the solution is to manage your source code and build paths so there's only one object file with a given name in the link. For example, make sure you're not compiling both a header file and a source file with the same base name as if both were source files. Or make sure you don't have both the retail and debug intermediate directories as part of your build path at the same time.

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    3 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.