Developer forum
cancel
Showing results for 
Search instead for 
Did you mean: 

UniString Compile Error

poco2013
Advisor
I am writing a small AddOn with uses a UniString constant. However, I copied the line from Element_Test which compiles and runs OK.
const GS::UniString text = L("This multistyle\nword w\u00E1s created\nby the Element Test example project.");
The above line gives a unresolved external error. Since the line compiles fine in the content of Element_Test, I assume there is a lib or something I need to include.

The errors are:

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) unsigned short const * __cdecl GS::DefineConstantUTF16CharacterOrString(wchar_t const *)" (__imp_?DefineConstantUTF16CharacterOrString@GS@@YAPEBGPEB_W@Z) referenced in function "int __cdecl CreateMultiTextElement(struct API_Coord const &,double,struct API_Guid const &)" (?CreateMultiTextElement@@YAHAEBUAPI_Coord@@NAEBUAPI_Guid@@@Z) AddOn C:\Users\gteac\Archicad_C++\Labels\AddOnMain.obj

Any ideas on how to fix??1
Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25
1 ACCEPTED SOLUTION

Solution
poco2013
Advisor
I found out what was causing the compile error. The problem occurs because I was using the default demo CMAKETEXT.txt file as supplied by Graphisoft to generate the VS build file.

I created a custom AddOn using snippets from the example files. One included: const GS::UniString which is a wchar_t. VS now treats that as a built-in function, Archicad, however, defines it as a typedef -- the old method.

There is a compiler switch to switch between the two but ON is the default. Graphisoft's Cmake does not include this option so by default, it is ON, which will result in a compile error if UniStrings are used within. The solution was to simply change the property switch to NO which will use the typedef.

Others may come across this problem in the future if you use Cmake. The NO option should be included in the Cmake txt file but might then cause other problems. This brings to mind that other compiler switches may be needed for other snippets of code. This should be defined in the examples.

Since Graphisoft may be moving, in the future, to use Cmake in their examples, they should recognize that it will make it easier to cut/paste from the examples but then compiler switch settings may be affected depending on what code is being reused.

I don't have a solution other than to suggest that more documentation from Graphisoft regarding Cmake's options be included in the demo files. Assuming that Graphisioft decides to use it.

Cmake can be very complicated, but as I see it, most of the commands/options are repeated in groups and are readily understandable once explained and only a few are used.

Hope this helps someone who may also come across this in the future.
Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

View solution in original post

2 REPLIES 2

Solution
poco2013
Advisor
I found out what was causing the compile error. The problem occurs because I was using the default demo CMAKETEXT.txt file as supplied by Graphisoft to generate the VS build file.

I created a custom AddOn using snippets from the example files. One included: const GS::UniString which is a wchar_t. VS now treats that as a built-in function, Archicad, however, defines it as a typedef -- the old method.

There is a compiler switch to switch between the two but ON is the default. Graphisoft's Cmake does not include this option so by default, it is ON, which will result in a compile error if UniStrings are used within. The solution was to simply change the property switch to NO which will use the typedef.

Others may come across this problem in the future if you use Cmake. The NO option should be included in the Cmake txt file but might then cause other problems. This brings to mind that other compiler switches may be needed for other snippets of code. This should be defined in the examples.

Since Graphisoft may be moving, in the future, to use Cmake in their examples, they should recognize that it will make it easier to cut/paste from the examples but then compiler switch settings may be affected depending on what code is being reused.

I don't have a solution other than to suggest that more documentation from Graphisoft regarding Cmake's options be included in the demo files. Assuming that Graphisioft decides to use it.

Cmake can be very complicated, but as I see it, most of the commands/options are repeated in groups and are readily understandable once explained and only a few are used.

Hope this helps someone who may also come across this in the future.
Gerry

Windows 10 - Visual Studio 2019; ArchiCAD 25

Viktor Kovacs
Graphisoft Alumni
Graphisoft Alumni
Thank you for pointing this out. We constantly try to make the compilation as close to Archicad's own compilation as possible. I've already known about this one, but it didn't cause any errors in Add-Ons before.

I've modified the CMake template here:
https://github.com/GRAPHISOFT/archicad-addon-cmake/commit/646a7067667586e38eff3e3378d24de7f2c58abc

Now the build option is turned off by default. Thank you again for the report!

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!