Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
(My IDE is Visual Studio 2019)
So, the question is about the macro UNICODE. Which works fine if there is only one source file in the project. However, if there are multiply source files, and UNICODE macro is defined only in one of them, linker gets angry and will show the error:
unresolved external symbol "wchar_t __cdecl getTChar(void)
which is caused by second.cpp file which does not have a UNICODE macro.

So a solution for the problem is not quite obvious (for me): setting project property "Character set" to "Use Unicode Character Set".
But i want to know how to do it without changing project property "Character set". Do i have to define UNICODE in every single source file?

What I have tried:

i tried to find the answer via Google and searched in the book "Windows Programming 5th edition" in chapter where this macro is explained.
Posted
Updated 22-Oct-20 5:12am

Quote:
Do i have to define UNICODE in every single source file?
Yes, you have to. You might, however, define it as a compiler option, see /D (Preprocessor Definitions)- To set this compiler option in the Visual Studio development environment | Microsoft Docs[^]
 
Share this answer
 
Comments
Avtem 22-Oct-20 11:00am    
Oh, so i see now. Thank you for your answer.
Well, it's great that we can set UNICODE macro this way=)
The link was very useful as well!
You can define it in the Project Properties in the Advanced -> Character Set box. This will ensure that all source files will be compiled with /D "UNICODE" as standard.
 
Share this answer
 
Comments
Avtem 22-Oct-20 11:21am    
"You can define it in the Project Properties" Yes, i knew that, it is written in my original post. And the second way CPallini pointed out a few minutes ago. But thank you for your answer!
Richard MacCutchan 22-Oct-20 11:26am    
Sorry, I missed that. But that is still the best way to do it.
CPallini 22-Oct-20 15:42pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900