Archicad C++ API
About Archicad add-on development using the C++ API.

Updating hotlinks: ..\Examples\ and ClickAnElem()

MudratDetector
Enthusiast

VS2017 and AC24

I am writing an Add-On to update all hotlinks in a project file.  I am starting with Do_UpdateHotlink() found in the  ..\Examples\Element_Test\Src\Element_Hotlink.cpp file.  This allows the user to select and update a single hotlink instead of all of them at once.

Do_UpdateHotlink() calls a function, SelectPlacedHotlinkByClickOnElement(), that is included in the same Element_Hotlink.cpp file found in ..\Examples\.

SelectPlacedHotlinkByClickOnElement() calls a function, ClickAnElem(), that is found in the .\APICommon.h  file [in the same folder as my Add-On .cpp file and .hpp file].

 

* * In Visual Studio, I can hover over the call to ClickAnElem() and see it expand to the balloon of argument requirements.

* * In Visual Studio, I can click on the call to ClickAnElem(), press F12, and see it jump to the .\APICommon.h file that contains the definition.

* * I can match the arguments I have provided with the argument requirements and I do not see an issue.

* * I have even added

 

 

#include ".\APICommon.h"

 

 

although I do not believe that is necessary.

 

But when I build...

 

 

1>JHP_DrawingUpdate.obj : error LNK2019: unresolved external symbol "bool __cdecl ClickAnElem(...
1>Build\x64\Release\JHP_DrawingUpdate.apx : fatal error LNK1120: 1 unresolved externals

 

 



My code is straight from the SelectPlacedHotlinkByClickOnElement() function in the ..\Examples file:

 

 

if (!ClickAnElem("Click on an element to select a hotlink instance", API_ZombieElemID, nullptr, nullptr, &guid)) {

 

 

I have even modified it to include the last two arguments with default values:

 

 

(!ClickAnElem("Click on an element to select a hotlink instance", API_ZombieElemID, nullptr, nullptr, &guid, nullptr, true))

 

 


I do not understand why that is my error since, by all my accounts, I am able to find the externally defined function.

What am I missing here?

Thanks again for the continued support,

Chris

Chris Gilmer
Intel i9-12950HX CPU @ 2.30GHz, 16 cores
NVIDIA GeForce RTX 3080
48.0 GB RAM
Windows 10 Pro 64-bit
2 REPLIES 2
kovacsv
Booster

The error means that the compiler found the function definition, but the linker wasn't able to find the compiled version (object file) of that function. Probably it was never compiled. Make sure to add "APICommon.c" (the c file, not the h) to your project. In Visual Studio you can right click on the project, and then select Add/Existing item.

MudratDetector
Enthusiast

Thanks for the reply.

 

I have added APICommon.c to the project in Visual Studio.

MudratDetector_0-1681745345937.png

 

After saving the project and hitting F7 to build, I was getting [error C3861: identifier not found] errors.  I solved this by copy/paste-ing the referenced functions from 'APICommon.c' into and above the call to those functions in my 'projectname.cpp' and commenting these out of the 'APICommon.c' file.  My menu item now builds without error and executes as expected.

 

However, I have to believe that my cut/paste/comment solution is not the path of least resistance.  Knowing that the placement/location of the function definition relative to the function call matters, is there a better way to accomplish this without having to resort to my cut/paste/comment solution?

 

Thanks again and thanks for the insight.

Chris

Chris Gilmer
Intel i9-12950HX CPU @ 2.30GHz, 16 cores
NVIDIA GeForce RTX 3080
48.0 GB RAM
Windows 10 Pro 64-bit