Skip to content

Instantly share code, notes, and snippets.

@cho0h5
Created June 5, 2024 01:03
Show Gist options
  • Save cho0h5/bbaedb8112d5e62623742b10b5b73431 to your computer and use it in GitHub Desktop.
Save cho0h5/bbaedb8112d5e62623742b10b5b73431 to your computer and use it in GitHub Desktop.
// gcc -lcurl curl_without_error_handling.c && ./a.out
#include <curl/curl.h>
int main() {
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "https://ziglang.org");
curl_easy_perform(curl);
curl_easy_cleanup(curl);
return 0;
}
// you should add the two lines below into build.zig
// exe.linkSystemLibrary("libcurl");
// exe.linkLibC();
// and the, run `zig build run`
const cURL = @cImport({
@cInclude("curl/curl.h");
});
pub fn main() !void {
const handle = cURL.curl_easy_init();
defer cURL.curl_easy_cleanup(handle);
_ = cURL.curl_easy_setopt(handle, cURL.CURLOPT_URL, "https://ziglang.org");
_ = cURL.curl_easy_perform(handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment