question

DeadStack avatar image
0 Votes"
DeadStack asked TheodoreTriandaphyllopoulos-2729 edited

LNK4042 object specified more than once; extras ignored

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

c++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Someone commented on another problem I'm having with VS and it made me think about the project file, and I noticed there was Win32 builds in there. So I went into configuration manager and disabled Win32 build. And that actually got rid of this linker error.

EDIT: No, this didn't actually work, it only worked for a while. VS sometimes takes several hours to update it's Intellisense database I guess, or it's just plain not understanding the source code at times, which I've seen before in C++ projects - It's pretty terrible.

0 Votes 0 ·
JeanineZhang-MSFT avatar image
2 Votes"
JeanineZhang-MSFT answered JeanineZhang-MSFT commented

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.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@DeadStack

May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·
Viorel-1 avatar image
1 Vote"
Viorel-1 answered TheodoreTriandaphyllopoulos-2729 edited

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks! You made my day (night actually).
I wouldn't think of it. I guess that I just misclicked when creating the project.
I had a bigger problem. Sometimes there were linker errors that objects in the said .obj were missing.
Until now I was just adding or deleting a blank line in the .cpp file and it worked (I understood that I thus forced a compile which resolved the references).

0 Votes 0 ·