-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I compile and run on the "Clion+Cygwin+Win7" platform? #4
Comments
Google Test is only needed to run the tests. I think that your CMake script is missing something like "target_link_libraries(YOUR_BINARY httpclient ${CURL_LIBRARIES}) because your binary (program) is not linked (statically) with the library. However, if you don't want to link the binary to a statically made library (I think that's your case, you forgot to mention HTTPClient.cpp in : add_executable(YOUR_APP main.cpp HTTPClient.cpp) Also don't forget to link libcurl to your app (e.g. : target_link_libraries(YOUR_APP curl) ) Hope that helps. PS : in your code, you have a bug : you need to feed std::unique_ptr a valid pointer so you can do something like this :
or even better, don't allocate the object in the heap, but instead in the main's stack 👍 (or a global variable)
If you need a CMakeLists.txt to run your demo, let me know. If you are not familiar with CMake, you can use a simple makefile, as you are working with an IDE, you have to choose one of these two options. You can also compile directly (g++) and use a text editor... |
According to your prompt, I succeeded. thank you very much. target_link_libraries(TestClion curl) Then I opened the "cygiwn64 setup" and installed the following to succeed. If the picture shows. When I was learning CPP, I was based on Visual Studio (because the university teacher taught this, the students around me were based on VS development), so I am not familiar with (CMake, MakeFile, Clang, gcc), I want to learn these things, Are there any recommended tutorials and books? |
curl is a program (like wget, you can use it in a terminal to download files) and libcurl-devel are the development files for libcurl (headers and compiled libraries for the OS you are running). You can also compile libcurl by yourself, I showed how to do this for Windows by using a batch script, in Linux you can also do the same thing, the issue is that you have to indicate the path of libcurl headers and its libraries to CMake. Same thing here, in university, they taught me Visual C++. I learnt "cross-platform" C++ by experience. The concept is not really hard : you have different C and/or C++ files, libraries (C and/or C++) and you have to make a "cake" with it (the cake can be a binary program that you will run, a static or shared library that you may link with another binary later). The obvious solution is to launch several commands involving the compiler (g++ or clang, e.g. g++ module1.cpp -o mo1, g++ module2.cpp -o mo2, g++ mo1 mo2 -o cake -lcurl -lpthread) you can also put all these commands in a shell file (windows or linux). For simple programs that is fine, but for more bigger ones, you will have many of these g++ instructions and it will be nightmare to manage them, so the solution is to use a makefile script (you can use them in Windows via Visual Studio, Linux, Unix, macOs etc...). when you run "make", the "Makefile" file will be executed by this tool to build you your cake. A Makefile has "rules", you can have a rule to build and run a unit test program, e.g. "make tests" another one to install the library somewhere (in /usr/lib for example - make install). Personally, I don't like writing makefiles (and it's not easy to write makefiles of portable programs), so under Windows/Visual Studio, the fastest solution is to create a visual studio solution that contains one or more projects (1 solutions -> 1 or more projects, 1 project -> 1 cake). Projects looks like Makefile's rules ! Tools like CMake, will allow you with a single script, to generate Makefiles (Linux/Unix, Visual Studio solutions etc... but the CMake has to be well written to achieve that goal ! Google CMake, you will find a lot of good resources to understand its system (I will send you a list later), you don't need to master it, just understand its concept (at first glance it's not clear). cmake -G "Visual Studio 17" => will generate Visual Studio 17 solutions (CMakeLists.txt has to be in the current directory, for Windows you may use the CMake-GUI interface). What I said applies for other programming languages (For Java, there's Maven etc...). The code is not enough to have the cake, the build system is also very important and it can be complex. After CMake, you can learn about CPack, that will help you to produce an installer (e.g. NSIS, auto extractible archive etc...) for your project (binary and libraries etc...). and finally, if you work on a big project with different persons, you may need control version (git - "history" of your source code and its branches) and CI/CD (continuous integration, continuous deployment) tools : gogs, redmine, jenkins, CDash (automate deployment/tests) etc... |
I read the documentation carefully and found that I needed libcurl and Google Test, then I successfully installed libcurl according to the documentation.
However, when installing GoogTest , need to install libgtest-dev via apt-get.
Google prompts me to use apt-cyg instead of apt-get and then run as follows:
When I get here, I can't go on. It seems that TestHttp can't be compiled successfully.
Later, I created a new project myself to test Http, but it still failed. The screenshot is as follows.
As for why I want Clion + Cygwin instead of Visual Studio, because I want cpp to compile the application, it can run on Ubuntu or Windows.
The text was updated successfully, but these errors were encountered: