-1

This question may seem stupid, but as a beginner I did encounter this question when I moved forward, and I couldn’t find any information.

https://upload.cc/i1/2020/12/30/rUEC9s.png

https://upload.cc/i1/2020/12/30/d7Gwbr.png

https://upload.cc/i1/2020/12/30/6vr3lQ.png

This is an open source C++ program, I tried to compile and run it, but it failed

I have the following confusion:

  1. Why the program does not have main.cpp

Update: When asking the first question, I even forgot helloworld.cpp, sorry

  1. How do I compile and run it with CLion

Update: Usually I create a new project. After I create the project, it seems that it can be compiled and run for granted, but I don’t know how to compile and run an existing project (from others).

  1. What do the folders in the first picture usually refer to

  2. What does cmake and CMakeList.txt mean?

  3. This open source program calls opencv, fftw and other libraries. I downloaded the corresponding files on the official website. How should the program call these libraries next? If I download the library package on the official website, how should I install or configure it; if I install the package using homebrew, does that mean I have already configured it? Or I just finished downloading

I have written some programs in c++ and qt, but I don’t seem to know anything about c++

Finally, there is really nothing in the readme of this project

Veasky
  • 45
  • 5
  • Nothing requires a `main.cpp`. One of the `.cpp` files must contain a `int main ()` -- nothing else is needed. `cmake` is how you build the program. Suggest building in an out of source directory, e.g. `mkdir ../build` and `cd ../buid` and then running `cmake ../path/to/source/with/CMakeList.txt` `cmake` is just another form of `make`. `CMakeList.txt` is what `cmake` uses for a `Makefile`. – David C. Rankin Dec 30 '20 at 16:02
  • 1
    You're asking many and some fairly broad questions. This is not on-topic for Stackoverflow. Each post must contain one narrow/specific question. Read more at [here](https://stackoverflow.com/help/on-topic). – Ted Klein Bergman Dec 30 '20 at 16:05
  • If you have installed `opencv` and `fftw` so the system knows where they are. Simply changing to your source directory with `CMakeList.txt` and typing `cmake` will start the build process. (of course you must have `cmake` installed -- which you likely do). Running `cmake` in the source directory will write all the object files and temporary files to that directory -- which is why building in an out-of-source directory is recommended. Your lack of knowledge with C++ isn't the issue, it is the lack of understanding of the cmake build process. It doesn't matter what language it is written in. – David C. Rankin Dec 30 '20 at 16:11
  • @DavidC.Rankin Thank you for your patience, I really don’t know anything about the cmake build process – Veasky Dec 31 '20 at 01:00
  • `cmake` really makes building projects easy on the end-user building the project. If the `CMakeList.txt` is correctly written -- all you need to do is type `cmake` and the project should build from there -- otherwise it will provide an error telling you what is missing. I like building out-of-source to keep the source directory clean. You can simply create a new directory somewhere, change to that directory, and then type `cmake /path/to/source/dir` to build the project. Good luck with the build. – David C. Rankin Dec 31 '20 at 01:06
  • @DavidC.Rankin CMakeList.txt should be cross-platform, right? That is, if CMakeList.txt is correct on Linux, then I just need to recompile it with cmake – Veasky Dec 31 '20 at 01:25
  • Yes. All a CMakeList.txt file does is coordinate the dependencies needed to build the program. Whether you are on windows or Linux, so long as your environment allows cmake to find the needed dependencies, then the project will build. Now there are some projects that are only written for one platform or the other and were never intended to be cross platform (i.e. projects incorporating the windows.h header file, etc..). You should be able to determine what platform is supported just be reading the requirements on the project web site or in the Readme.txt or Install.txt files. – David C. Rankin Dec 31 '20 at 02:08
  • @DavidC.Rankin At present I have generated a new `Makefile`, I started to execute `make` but something went wrong (missing `SuiteSparseQR.hpp`), I downloaded the `SuiteSparse` package, and threw the whole package into the `include` directory, nothing Change; later I tried to put the `.hpp` file in the `SuiteSparse` package into the `include` directory. Is this correct? (Although there are new and other errors) – Veasky Dec 31 '20 at 04:55
  • `SuiteParse` is likely a library that must be compiled and installed. The `SuiteSparseQR.hpp` provides the package you are compiling with the function prototypes for the function in the `SuiteParse` package. Sometimes you have to install dependencies one-by-one until you get `cmake` to run. If the package you are building doesn't provide a concise list of dependencies, you can read the CMakeList.txt, more or less, and look at what is being included/required. Each level of your source package will have it's own CMakeLists.txt file. So you may have to look in more than one. – David C. Rankin Dec 31 '20 at 05:01
  • @DavidC.Rankin There is a `Makefile` file in the package directory, does it mean that I should execute the `make` command directly on it? and then? Put the whole package directly into the `include` directory of the project? Or other folders? (I have used `make` for the `Makefile` file in the package directory, but it hasn't ended yet) – Veasky Dec 31 '20 at 06:56

2 Answers2

0

Your questions are too broad. Generally speaking, the answers would be something like this:

  1. Naming your main file main.cpp is a convention, but is not required. What is required is a main() function (More info here).

  2. You have to configure CLion to open Makefiles. There is a tutorial in CLion's website (Here).

  3. What documents do you refer to?

    • src: Naming convention to the folder where the source (.cpp) files go.
    • include: Naming convention where the header (.hpp) files go.
    • License.txt: Where the software's license is written.
    • readme.md: Document that gives information about the project.
    • tests: Files to test the software.
  4. cmake is a tool designed to build and package software (Their website is here). CMakeLists.txt is the file CMake uses to know how to create a Makefile and build the program.

  5. You have to make the system know where the libraries are. You can achieve this by adding them to the project's folder or by adding them to the PATH of your compiler.

If you don't know very much about of C++ you should probably search a good C++ textbook. However, remember that Makefiles and C++ are 2 completely different things.

Gary Strivin'
  • 908
  • 7
  • 20
0

Most open source programs have build instructions somewhere in the readme.

It is usually best to follow those, even if they require downloading unfamiliar tools.

If the project doesn't have (detailed) build instructions, you should ask the owner, to add (more detailed) build instructions(by for example creating an issue for git-based repositories).

QuantumDeveloper
  • 737
  • 6
  • 15