1

I'm getting a linker error because of a conflict between liburctd.lib and libmmt.lib. Why I'm getting that is a whole other question.

In trying to figure that out, I wanted to see if just setting /NODEFAULTLIB (or -nodefaultlib) worked.

I've tried three different ways of adding it (with three different libraries to be able to distinguish the errors, slashes/dashes/uppercase/quotes all don't make a difference):

set_target_properties(SA PROPERTIES LINK_FLAGS -nodefaultlib:libcmt.lib)
target_link_options(SA PUBLIC -nodefaultlib:libmmt.lib)
target_link_libraries(SA PUBLIC -nodefaultlib:liburctd.lib)

Running with verbose commands shows me:

LINK: command "C:\PROGRA~2\Intel\oneAPI\compiler\latest\bin\icx.exe /nologo @CMakeFiles\SA.rsp /Qoption,link,/machine:X86 /Qoption,link,/debug /Qoption,link,/INCREMENTAL /Qoption,link,/subsystem:console -nodefaultlib:libcmt.lib -nodefaultlib:libmmt.lib /link /out:SA.exe /implib:SA.lib /pdb:SA.pdb /version:0.0 /MANIFEST:EMBED,ID=1" failed (exit code 1169) with the following output:
icx: warning: unknown argument ignored in clang-cl: '-nodefaultlib:liburctd.lib' [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl: '-nodefaultlib:libcmt.lib' [-Wunknown-argument]
icx: warning: unknown argument ignored in clang-cl: '-nodefaultlib:libmmt.lib' [-Wunknown-argument]
libucrtd.lib(log_impl.obj) : error LNK2005: __CIlog already defined in libmmt.lib(log_iface_c99.obj)
libucrtd.lib(pow_impl.obj) : error LNK2005: __CIpow already defined in libmmt.lib(pow_iface_c99.obj)

Focusing in on the important part of the command:

... -nodefaultlib:libcmt.lib -nodefaultlib:libmmt.lib /link /out:SA.exe  ...

I read somewhere that -nodefaultlib is a flag that needs to come after /link

And indeed, running the command manually with -nodefaultlib:libmmt.lib after /link makes my program link just fine!

What is happening, why is it happening, what am I doing wrong?

I've been looking for the better part of 4 hours yesterday and I can't for the life of me find anything at all about this.


(If someone has a solution for my linker error, which oddly enough occurs in my 32 bit debug build but not in my 64 bit one, that's also much appreciated)

1 Answer 1

2

It should be configured like below, as you have shown other linker options in the question.

target_link_options(SA PUBLIC /Qoption,link,/nodefaultlib:libmmt.lib)

AFAIK target_link_libraries as shown is not needed, otherwise the option is duplicated.

Sign up to request clarification or add additional context in comments.

1 Comment

Holy sh*t that works. Am I dumb for thinking that "target_link_options" should have added my link option in the way a link option is apparently supposed to be added? Also: those other linker options I've shown aren't mine, so I disregarded them as some verbose mumbojumbo that cmake just adds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.