0

I dont know why but if I include curl_easy_init() in my code, all my console output will be omitted. no matter it is executed before or after the function is called.

This code below would output "Helo" as expected.

#include <iostream>
#include <curl/curl.h>
using namespace std;
int main(){
    std::cout<<"Helo"<<std::endl;

    CURL *asd;
    // asd = curl_easy_init();
    return 0;
}

But this wouldn't output ANYTHING on console.

#include <iostream>
#include <curl/curl.h>
using namespace std;
int main(){
    std::cout<<"Helo"<<std::endl;

    CURL *asd;
    asd = curl_easy_init();
    return 0;
}

The console looks like this when I ran these 2 snippet.

PS C:\Users\Administrator\Desktop\Test> cd "c:\Users\Administrator\Desktop\Test\" ; if ($?) { g++ -std=c++17 test2.cpp sqlite3.o -lcurl -DCURL_STATICLIB -o test2 } ; if ($?) { .\test2 }
Helo
PS C:\Users\Administrator\Desktop\Test> cd "c:\Users\Administrator\Desktop\Test\" ; if ($?) { g++ -std=c++17 test2.cpp sqlite3.o -lcurl -DCURL_STATICLIB -o test2 } ; if ($?) { .\test2 }

I am using vscode with code runner and I downloaded my compiler with mingw. I downloaded "curl-8.2.0_1-win32-mingw" and copied the files in "lib" and "include" into the files in mingw accordingly. i dont know what i did wrong! can anyone help me??

edit:

PS C:\Users\Administrator\Desktop\Test> cd "c:\Users\Administrator\Desktop\Test\" ; if ($?) { g++ -Wall -Wextra -pedantic -O2 -std=c++17 test2.cpp sqlite3.o -lcurl -DCURL_STATICLIB -o test2 } ; if ($?) { .\test2 }
test2.cpp: In function 'int main()':
test2.cpp:7:11: warning: variable 'asd' set but not used [-Wunused-but-set-variable]
     CURL *asd;
           ^~~
top
  • 1
  • 3
  • And you linked the compiled code with libcurl exactly how? – Sam Varshavchik Jul 20 '23 at 11:44
  • my guess would be that your code is simply crashing, have you tried using a debugger? – Alan Birtles Jul 20 '23 at 11:46
  • i added "lcurl" and "DCURL_STATICLIB" flag in the compiler. i used `cd "c:\Users\Administrator\Desktop\Test\" ; if ($?) { g++ -std=c++17 test2.cpp sqlite3.o -lcurl -DCURL_STATICLIB -o test2 } ; if ($?) { .\test2 }` as the command for compiling – top Jul 20 '23 at 11:48
  • how do i debug the executable? – top Jul 20 '23 at 11:49
  • 1
    Does this answer your question? [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – jabaa Jul 20 '23 at 11:58
  • thanks. i found out that it didnt even compile. but the compiler did not show any error on why it doesnt compile an exe for my code. and with the debugger included in vscode, it said "No problems have been detected in the workspace" instead of debugging anything. probably due to the code doesnt actually compile. – top Jul 20 '23 at 12:02
  • actually it did compile. first i deleted test2.exe. then i did `g++ -std=c++17 test2.cpp -lcurl -o test2` which infact did compile test2.exe. and when i do `.\test2.exe` it outputs nothing – top Jul 20 '23 at 12:08
  • 1
    This is the point, where you start using the debugger. Remember to compile with debugging symbols. I recommend using an IDE that supports debug builds and debugging out of the box without complex configuration. VSCode isn't one of these IDEs. – jabaa Jul 20 '23 at 12:09
  • 1
    Using VSCode to learn C++ is like going to shop for groceries on a Boeing 737. It is a complicated IDE, that requires complex configuration and existing knowledge of complex technologies, like JSON, to work correctly. Beginners will find it much easier to use plain text editors, and using simple, basic tools like makefiles to build their first C++ programs. – Sam Varshavchik Jul 20 '23 at 12:16
  • I cannot figure out a way to debug. but i turned on all the warnings for C++. i got this warning. but not an error. see the edit thanks – top Jul 20 '23 at 12:17
  • @SamVarshavchik Using textfiles and makefiles may be a good way learn how to code, but using a C++ debugger without an IDE can be a pain for beginners. I hate gdb with and without GUI, even after more than a decade. – jabaa Jul 20 '23 at 12:22
  • Funny that you mentioned that, @jabaa, The other day I discovered that `gdb` includes a curses-based source browser. – Sam Varshavchik Jul 20 '23 at 12:23
  • I recommend a good IDE, e.g. Eclipse CDT, Visual Studio (not Visual Studio Code) or CLion, at least for debugging, until you've learned the basic concepts of debugging. – jabaa Jul 20 '23 at 12:27
  • 1
    https://stackoverflow.com/questions/50349623/c-libcurl-crash-when-init-curl-global-init-and-curl-easy-init i think this is related but i have no idea what is the answer talking about. – top Jul 20 '23 at 12:29
  • 1
    Do you see `Process finished with exit code -1073741515 (0xC0000135)`? – jabaa Jul 20 '23 at 12:34

0 Answers0