License delivery maintenance is planned for Saturday, July 26, between 12:00 and 20:00 CEST. During this time, you may experience outages or limited availability across our services, including BIMcloud SaaS, License Delivery, Graphisoft ID (for customer and company management), Graphisoft Store, and BIMx Web Viewer. More details…

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

Why can't Add-On be used when I use curl?

luna
Contributor

I am developing with AC24 and VS2017.

 

I want to use curl to access the Http interface and use JsonCpp to parse the data, but every time #include <curl/curl.h>, the Add-On doesn't work.

When I remove the #include <curl/curl.h> code, the plugin works fine.

 

Is this a version problem or some other reason, please give me some tips.

 

addonquestion.png

 

 

9 REPLIES 9
luna
Contributor


The reason I found some details was the Get and Post functions, and when I added these two methods to the file, AddOn didn't work.

 

CURLcode HttpUtils::PostUrl(const string &url, string& response, const string&token, const string&postParams) {
	CURL*m_curl = curl_easy_init();
	CURL* m_curl = curl_multi_init();
	
	if (m_curl) {
		struct curl_slist* head_list = NULL;
		head_list = curl_slist_append(head_list, "Content-Type:application/json; charset=UTF-8");
		if (!token.empty()) {
			string tokenstr = "token:" + token;
			head_list = curl_slist_append(head_list, tokenstr.c_str());
		}
		//tenant_id = "tenant-id" + const_;
		head_list = curl_slist_append(head_list, tenant_id.c_str());
		head_list = curl_slist_append(head_list, "Changhong-type:ARCHICAD");
		head_list = curl_slist_append(head_list, std::string("Authorization:Bearer " + token).c_str());
		curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, head_list);
		curl_easy_setopt(m_curl, CURLOPT_HEADER, 0);
		curl_easy_setopt(m_curl, CURLOPT_POST, 1);
		curl_easy_setopt(m_curl, CURLOPT_URL, url.c_str());
		if (!postParams.empty()) {
			curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, postParams.c_str());
		}

		
		curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, req_reply);
		curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, (void *)&response);

		curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1);

		
		curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT, 20);
		curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, 20);

	
		m_rescode = curl_easy_perform(m_curl);

	}
	curl_easy_cleanup(m_curl);
	return m_rescode;
}
CURLcode HttpUtils::GetUrl(const string &url, string& response, const string&token) {
	 CURL*m_curl = curl_easy_init();
	if (m_curl) {
		struct curl_slist* head_list = NULL;
		head_list = curl_slist_append(head_list, "Content-Type:application/json;charset=UTF-8");
		if (!token.empty()) {
			string tokenstr = "token:" + token;
			head_list = curl_slist_append(head_list, tokenstr.c_str());
		}
		head_list = curl_slist_append(head_list, tenant_id.c_str());
		head_list = curl_slist_append(head_list, "Changhong-type:ARCHICAD");
		head_list = curl_slist_append(head_list, std::string("Authorization:Bearer " + token).c_str());
		//head_list = curl_slist_append(head_list, "token:"+);
		
		curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, head_list);
		curl_easy_setopt(m_curl, CURLOPT_URL, url.c_str()); // url  
		curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, false); // if want to use https  
		curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYHOST, false); // set peer and host verify false  
		curl_easy_setopt(m_curl, CURLOPT_VERBOSE, 0);
		curl_easy_setopt(m_curl, CURLOPT_READFUNCTION, NULL);
		curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, req_reply);
		curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, (void *)&response);
		curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1);
		curl_easy_setopt(m_curl, CURLOPT_HEADER, 0);
		curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT, 3); // set transport and time out time  
		curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, 3);

		curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT, 6);
		curl_easy_setopt(m_curl, CURLOPT_TIMEOUT, 6);

		// open post request
		m_rescode = curl_easy_perform(m_curl);

	}
	curl_easy_cleanup(m_curl);

	return m_rescode;
}

 

🙂

luna
Contributor

More specifically, the problem is with the curl_easy_  method.

 

addonquestion2.png

ManelCG
Contributor

Hello,

 

The issue is most likely that curl is being linked dynamically. We also had this problem.

 

The most likely solution is to try to force Curl to be linked statically. That is, if on Windows, force it to compile as .lib and then link the .lib on it.

 

Generally, AC will give that error whenever it cannot find a dll, which will be almost every time when you link something dynamically.

 

I also recommend to give libcpr a try. It is a very, very easy to use and to include curl wrapper.

 

Good luck!

Nathan676
Contributor

Hey, I am running into the same problem. Did you end up finding a solution?

Hi Nathan,

 

How are you including curl in your project?

 

I'm using following CMake approach and it works for me:

find_package (CURL REQUIRED)
target_link_libraries (AddOn PRIVATE CURL::libcurl)

Hey Bernd,

 

I am also using CMake, when I add what you have to my CmakeLists.txt I get a error "cmd.exe" exited with code 1.

 

How have you added that into your project?

ileads
Participant

Your issue seems to be related to a conflict or incompatibility between the curl library and the Archicad Add-On development environment. Here’s a detailed breakdown of what might be going wrong and how to address it:


Problem Summary

You’re developing an Archicad 24 Add-On using Visual Studio 2017. When you include:

#include <curl/curl.h>

Your Add-On fails to load or run properly. But when you remove that line, everything works.


Likely Causes & Solutions

1. ⚠️ Binary Compatibility / CRT Mismatch

Archicad Add-Ons must match the runtime environment of the host application. If you’re using libcurl built with a different C runtime (CRT) than what Archicad uses, it can cause runtime crashes or the Add-On to silently fail.

Solution:

  • Make sure you compile libcurl with the same runtime settings as Archicad (e.g., /MD or /MDd).

  • Use static linking if necessary to isolate dependencies.

2. 🧩 DLL Conflicts

If libcurl loads its own dependencies (like OpenSSL, zlib, etc.) and those clash with what Archicad expects or already has loaded, the Add-On might silently fail to initialize.                                                                                                                                                                                                   vintage mortgage leads

Solution:

  • Try using a statically linked version of libcurl to avoid runtime DLL conflicts.

  • If using dynamic linking, ensure that libcurl and its dependencies are compatible and properly loaded.

3. 🧱 Symbol Collision

libcurl or one of its headers might introduce symbols that clash with those used internally by Archicad or its SDK.

Solution:

  • Wrap your curl includes in a separate translation unit (e.g., CurlWrapper.cpp) and limit exposure via headers.

  • Use extern "C" guards carefully if mixing C and C++ headers.

4. 🏗Build Configuration

Check that your build architecture matches:

  • Archicad 24 is 64-bit, so use 64-bit curl binaries and build settings.

  • Don’t mix Debug and Release CRTs when linking.

5. Add-On Verification Fails

Archicad validates Add-Ons before loading. If libcurl introduces something Archicad doesn’t like (e.g., missing dependencies or unexpected exports), it may reject the Add-On.

Solution:

  • Run Archicad with logging enabled and check the GSAddOn.log (or similar logs) for clues.

  • Try progressively including only parts of curl.h to isolate the issue.


 Recommendations

  • Use a minimal example where you only include curl.h and nothing else to confirm the breakage point.

  • Consider using vcpkg or conan to manage libcurl with controlled configurations.

  • Use delay loading for curl DLLs (#pragma comment(linker, "/DELAYLOAD:curl.dll")) if dynamic linking is necessary.


 Alternative Approach

If integrating libcurl proves too complex, you might consider using Windows-native APIs like WinHTTP or WinINet for HTTP access, which are generally more predictable within Archicad's plugin ecosystem.


If you can share the exact error message (e.g., from Archicad’s Add-On Manager or VS output), I can help pinpoint the failure further.

Hi Nathan,

 

My bad, I forgot that my project I copied from has a vcpkg setup. Which I don't recommend.

Instead I'm now using FetchContent and got it to work well. Please ignore the above and try this instead:

 

include (FetchContent) # Near the beginning of the CMakeFile. Needs CMake 3.11+

...
...
...

# Use a newer commit if necessary
FetchContent_Declare (curl
	GIT_REPOSITORY https://github.com/curl/curl/
	GIT_TAG de7b3e89218467159a7af72d58cea8425946e97d # v8.7.1 as of 2024-04-25
)
set (BUILD_CURL_EXE OFF)
set (HTTP_ONLY ON)
set (BUILD_LIBCURL_DOCS OFF)
set (BUILD_MISC_DOCS OFF)
set (ENABLE_CURL_MANUAL OFF)
set (BUILD_TESTING OFF)
set (BUILD_SHARED_LIBS OFF)
set (BUILD_STATIC_LIBS ON)
set (CURL_USE_LIBPSL OFF)
set (CURL_USE_LIBSSH2 OFF)
if (WIN32)
	set (CURL_USE_SCHANNEL ON)
else ()
	set (CURL_USE_SECTRANSP ON)
endif ()

FetchContent_MakeAvailable (curl)
target_link_libraries (AddOn PRIVATE CURL::libcurl)
target_compile_definitions (AddOn PRIVATE CURL_STATICLIB)

 

Since our team are all using Windows computers I decided to use WinHTTP and worked like a charm. Thanks for everyones help