Sending your c++ project [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have coded an app in c++ using the SFML library. I configured it into code blocks to run the program. Let's say I now want to send this app to my friend, what's the best way I can do this so that he doesn't have to go through downloading a lot of stuff to run it?
I am using the MinGW compiler.

Create an installer or package. For example; On RedHat Linux you'd want to create a RPM package. On Windows you want to create a MSI file. Whatever you do, the package you create should bundle up everything your application needs to run and put it into the correct location(s) on the target system. This includes your executable but also any libraries you use (including your compilers runtime libraries).

In most cases just shipping your .exe and all of its dependancies is enough.
In some cases you may also need to ship other files needed to run the application like configuration files, images, icons...
You can use copypedeps with the -r flag from https://github.com/brechtsanders/pedeps to copy your .exe along with its dependancy .dll files into an empty folder.
Then you can just zip everything in that folder and send it to somebody who can just unzip it an run the .exe.
Or you can make a proper installer to distribute the same files.

Your program needs some .dlls to run: some are the system ones, some are shipped with the compiler, and some come from the libraries you use (SFML). You need to ship all those .dlls (except the system ones) with your .exe, and they should be in the same directory.
It doesn't really matter if you make a proper installer or send your friend a zip archive. (If it's an archive, they might have to manually extract it before running the .exe.)
The question is how to figure out which .dlls to ship. There are several approaches:
Open the console, cd to where your .exe is, do set PATH= and try running the executable by typing its name. Since the compiler installation is no longer in the PATH, it shouldn't see the .dlls in there, and it should complain about them being missing. After you provide one .dll, it will ask for the next one.
A more civilized approach is to use a tool like ntdll to list all .dlls your app uses. Then copy them, ignoring the system ones (located in C:\Windows or subdirectories).
Note that both approaches rely on there being no extraneous .dlls in C:\Windows or subdirectories; some poorly written installers like to put their own .dlls in there. To check for that, make a list of all .dlls that come with your compiler (they should be in the same directory as the gcc.exe), and the ones that come from your libraries (SFML). Then look for the .dlls with the same name in C:\Windows and subdirectories, and if you find any, remove them.

Related

How to compile and run a C++ open source program? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
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:
Why the program does not have main.cpp
Update: When asking the first question, I even forgot helloworld.cpp, sorry
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).
What do the folders in the first picture usually refer to
What does cmake and CMakeList.txt mean?
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
Your questions are too broad. Generally speaking, the answers would be something like this:
Naming your main file main.cpp is a convention, but is not required. What is required is a main() function (More info here).
You have to configure CLion to open Makefiles. There is a tutorial in CLion's website (Here).
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.
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.
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.
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).

How to check the dll files required by my c++ file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I use Visual Studio 2017 Community for C++ coding. I have made a simple win32 console app and do not want to expose my code. I have also found the .exe file in the debug folder of the solution. When I try copying the .exe file in the Debug folder in another folder it says that the dll isn't found.I also tried copying the whole folder but the same error occurs. Please help me...I want to run my app on another computer also.
You can Generate Code Map for Solution.
Navigate to Architecture –> “Generate Code Map for Solution”
Generates a code map like:
Which shows the inter-dependency between modules and libraries.
In your case by just copying the exe, you are breaking the references to all of the required libraries. Depending on your scenario, you have two good options. Copy the entire source tree + dependencies for you project and recompile it in the new working directory or create an installer which will allow you to distribute dlls and any other required resources.
This is more complicated that one might hope. To answer the question in the title, you need Dependency Walker. (The web site doesn't mention Windows 10, but this stuff hasn't changed much recently, so don't worry about that.)
To distribute the program to another machine, you need to create a release build (the debug run-time libraries are not redistributable). Once you have done that, you will almost certainly find that the other machine already has the release run-time library, but you will need to copy other libraries.

Compile C++ Code in Windows 7 ("g++" command not recognized) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm writing a basic C++ program in Windows 7 that I am hoping to compile from itemindiv.cpp, itemindiv.h, item.cpp, item.h, container.cpp, container.h, and main.cpp. I've tried installing g++ and when I type "g++" command line, it doesn't recognize the command. I can't find a simple way to compile these files together, which was easy in command line on a unix system. Is there an easy way to compile this so I can interact with basic input and output (text based)?
Using g++ on windows via the command line is entirely viable through the use of something like MinGW or MinGW64, and you do not need to install Visual Studio to do it. However, it must be configured properly!
Notably, when running something from a command line, it's important to make sure it's fully installed and "on the path". The PATH is essentially a list of locations Windows will look for the program you're trying to run in.
Your first step should be locating g++ on your machine, and I assume in the install directory. This will not only tell you if you if it was installed correctly, but will help us configure the path. Generally, files you can run are going to be located in a /bin folder. In the case of MinGW64, this is located with in the installation directory.
On my machine for example, g++ is located at C:\mingw64\bin\g++.exe, which is where I ended up installing MinGW. You can also force windows to run g++.exe by providing the full path to it in the command line, regardless of if it's on the windows PATH or not. In my case, this may look as follows: C:\mingw64\bin\g++.exe myfile.cpp -o output.exe
If you are able to find the executable but it won't run from CMD/Powershell, this very often means that either the path doesn't include the install directory. Lets fix that.
Putting g++ on the path
Figure out the folder that the application is located in. In my case, this is C:\mingw64\bin\, but the location of g++.exe on your machine may and probably will vary.
Add your directory to the path: This can be done manually as follows, or with the help of a tool like EVEditor. This process is covered in a few other stack overflow answers as well, but I'll go over it quickly here:
In windows 7, right-click on My Computer and click Properties, then click on the advanced tab. In the advanced section, there should be an environment variables button, which should pop up a window titled Environment Variables.
Highlight the path variable, and click edit. The path is made up of semicolon ; delimited entries, and so we can and modify it to include C:\mingw\bin; (or wherever g++ is located for you) at the front - note the addition of the semicolon at the end of the filepath! It's important you do not delete what is already on the path, or this may impact the ability of other programs on your machine to run! In addition, windows searches the path in the order specified: front to back. If you have two folders, both with g++.exe in them, the first one appearing on the path will be used.
Once you've added it to the path, make sure you've restarted CMD/Powershell so your changes to the path are applied!
Note: If you think you added something to the path but it's still not accessible from the command line, you can have windows dump out what it thinks the path is in a given terminal window with echo %PATH%.
You need to install Microsoft Visual Studio and the create a C++ project.
Ensure to select to install Visual C++ modules during the Microsoft Visual Studio installation.

Where Should One Place Third Party Libraries? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
This may seem a bit ridiculous to ask, but I'm struggling to find a good system for this. Are there any standardized systems for storing and organizing third party development libraries? I'm plagued with OCD and consider myself to be a "neat-freak," so I tend to use tons of directories/subdirectories for organizing items, but since I'm a newer developer, I just recently started dabbling with 3rd party libraries and I'm not sure how to go about organizing them. I would use a ton of folders and make a huge hierarchy, but doing that may result in some extremely long absolute paths in the #includes of my source code. Any suggestions?
Third party libraries can go anywhere you want, as long as you make sure that both the compiler and the compiled program can find the files that they need. So you can go wild with organizing your files in whatever you want, as long as you make sure that you tell this to the compiler and the compiled program.
Exactly how to do this depends on the IDE (integrated development environment) that you are using. I use visual studio, so the exact terminology might be different if you use something else. In visual studio, you have to go to the properties of your project to do this.
For the header files of your external libraries, go to Configuration Properties > C/C++ > General and click on "Additional Include Directories". If you edit the value of this field, you can add the paths to the include directory of your external library, which should hold all the header files of the external library. By using the Macros that Visual Studio provides, you can make these paths relative, so that you don't have to do this all over whenever you move your project. Make sure you don't remove "%(AdditionalIncludeDirectories)". Also make sure that the selected configuration and platform at the top of the window match the configuration and platform for which you are trying to compile. Using the macros you can set this up for all the configurations and platforms simultaneously, which is a bit harder but it will save you time in the long run. An example from one of my projects:
$(SolutionDir)dependencies\SDL2_image-2.0.1\include;$(SolutionDir)dependencies\SDL2-2.0.5\include;%(AdditionalIncludeDirectories)
For the library files, you need to go to Configuration Properties > Linker > General and click on "Additional Library Directories". Edit this value to add the paths to the lib folders of your external libraries. You can again use macros here.
$(SolutionDir)dependencies\SDL2-2.0.5\lib\x64;$(SolutionDir)dependencies\SDL2_image-2.0.1\lib\x64;%(AdditionalLibraryDirectories)
Next, go to Configuration Properties > Linker > Input and edit "Additional Dependencies" to add the names of the .lib files that you need. Just the filenames this time, you don't need the path here. An example from one of my projects:
SDL2main.lib;SDL2.lib;SDL2_image.lib;%(AdditionalDependencies)
Finally, you need to make sure that your compiled program can find the .dll files of your external libraries. For this you can mess around with system variables like PATH and so on, but I don't recommend that. I prefer to use a Post-Build Event. An event like this is basically a sequence of command line commands that are carried out after your program has been compiled. You can add this event by going to Configuration Properties > Build Events > Post-Build Event and editing "Command Line". An example of what you can put here, from one of my projects, is shown below:
copy /Y "$(SolutionDir)dependencies\SDL2_image-2.0.1\lib\$(PlatformTarget)\*.dll" "$(TargetDir)*.dll"
copy /Y "$(SolutionDir)dependencies\SDL2-2.0.5\lib\$(PlatformTarget)\SDL2.dll" "$(TargetDir)SDL2.dll"
xcopy /Y /S /E /I "$(SolutionDir)assets" "$(TargetDir)assets"
Note that I use macros again: $(SolutionDir), $(PlatformTarget), $(TargetDir) are replaced by the solution directory, platform target and the target directory respectively for each combination of Configuration and Platform.
You have 2 options:
Use system-installed libraries (and headers), tell compiler where to find them.
Use a folder in your project (use folder ./external to store external sources, e.g. ./external/boost-asio for Boost ASIO library), download sources when initializing the project (I prefer to use git submodules to download external sources), and build them with your project.
CMAKE is a build tool which can help you in achieving both.
Either way, as jtbandes wrote, don't use absolute paths.

C++ Development Flow with 3rd Party Dependency [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm a Python developer with some background in another language such as Ruby.
In both language, dependency is managed by package manager automatically, such as pip or gem. Anyone could install such dependency by calling pip install -r requirements.txt, and it will install the necessary dependency via Python Package Index. Although, there has been an option to build the dependency manually from the source and install into the project, it is not a recommended process, and I have not done it.
I notice that C++ unfortunately have different nature in how dependency is being resolved for some reason. (e.g. different compiler flavor, compiler parameters, platforms, etc...)
At the moment, I am learning C++ using VS2015. and I have been stumbled again and again upon these library dependencies matter. With VS2015, there is a dependency package manager like python, and it is NuGet. However, not every library is available in NuGet, in fact, there are a lot of library developed independent from its IDE.
First I'm trying to use Boost. There is a manual on how to build the project, but I'm not sure what I need. Do I need to build from source? or Perhaps I just need a library that has been readily available?
Same reason for another library that I found. (e.g. QT, yaml-cpp, googletest, etc..)They only have a document how to build, instead of how to install as dependency.
And Ultimately, I will need to use lots of 3rd party library to be more productive. So, here's some of my questions that are very related.
How do C++ developer normally include 3rd party library into their project (the flow of installation 3rd party library)?
Do I have to build from source everytime I want to include? or perhaps you just need the header file which you could just copy and paste into your project directory?
I'm working in team (git), do each of my team need to build the dependency manually? Can it be automate such that the process of including new library is transparent for everyone?
Or perhaps, I don't really understand what specific question do I need
to ask. But why it is so painful to reuse library in C++?
Do I miss some fundamental understanding of C++ environement?
I'm not sure how much relevance it is, but CMake as a build tool that most library uses to build their project. Do I really need to build these library project?
More Questions:
After building some libraries, some of them generate static library .lib or dynamic library .dll to be included into the project. So is it correct to copy these generated library in our project? Should this be committed into the source version control? Some libraries are very large, and we don't want to maintain it. Yet we need the entire team to get the library transparently.
I understand you situation quite well. You cannot see the forest because too many trees are standing in your way...
Let me get one thing clear before I start to address your specific questions:
Generally speaking, dependencies in C++ are not more complicated than in Python.
The command pip install -r requirements.txt will establish an internet connection and download the necessary libraries and files from a repository server to fulfill the requirements. Under the Linux operating system (Ubuntu) the command: sudo apt-get install libboost-all-dev installs all required dependencies for boost. This is possible because there is a whole environment with servers that hold source-code as well as libraries and binaries that work together with the client programs (apt-get) that use it. This is exactly the same thing that the authors of pip have done for microsoft windows. microsoft themselves have never done this at the operating system level. They always left that to the programmer. NuGet is microsofts attempt to make-up for past mistakes.
Having this out of the way, let me address your questions:
It depends on the size of the 3rd party library. Small libraries like pugixml can be included as source in the source tree of your project. Bigger libraries like boost are better included as binary object code (library objects). Not all libraries do have binaries available to download (boost has), so you might be required to build from source. Bear in mind that all binaries are required to be built with exact the same compiler that you use in your project. The general steps to include it in your VS-Project:
Get the distribution files (either build from source or download and install binaries)
Add include paths to your Project:
Project > "projectname" properties > Configuration Properties > C/C++ > General > Additional Include Directories
Add paths to libraries:
Project > "projectname" properties > Configuration Properties > Linker > Input > Additional Dependencies.
No. You normally just use the header file. But it's better to add the path of the library into your project instead of copying the header file, because some projects (boost) have a huge hierarchy of header files.
It is a good idea that each member of your team has the same development environment with the same set of libraries installed. There are tools for this task: Chocolatey builds on top of NuGet and is therefore windows-affine. Vagrant deals with virtual boxes ands thus offers cross-platform development environments.
But more important is a decent source-control-management system. If you don't already use one - start using one Today!. This is the main collaboration-tool. It can really save your neck if you loose a developer machine.
There is another dependency problem: We've only addressed the development dependencies above. There is the problem of deployment dependencies:
your customers will need the libraries (*.dll files) that you have used for the development. You will need to package them as well into your deployment package (Installer). This is another issue which is probably already answered on SO.
Qt: if you start using Qt, I'd suggest that you start using their development environment Qt-Creator. This will automatically handle all dependencies. It will automatically detect the Visual Studio Compiler that you have installed, and use it. The IDE is quite close to Visual Studio.
CMake: No, it is not always required to use CMake to build a library project, some also include Makefiles. Others use CMake to produce Makefiles. "Follow the instructions" is the best advice I can give here.
Update 2015-10-24: paragraph point three reworked
How do C++ developer normally include 3rd party library into their
project (the flow of installation 3rd party library)?
It depends... There are a lot of ways, how to redistribute C++ libraries.
Do I have to build from source everytime I want to include? or perhaps
you just need the header file which you could just copy and paste into
your project directory?
For now, most C++ libraries contains two parts: binaries + header files. But often, there are a lot of problems, if compiler version of library is different with your compiler.
I'm working in team, do each of my team need to build the dependency
manually? Can it be automate such that the process of including new
library is transparent for everyone?
It depents on your team guidelines. You can choose what you want.
Or perhaps, I don't really understand what specific question do I need
to ask. But why it is so painful to reuse library in C++?
Because of some legacy of C. And because C++ is low-level language in compare with python/java/c#. C++ is supported by a lot of different platforms, including embedded. And ofter, it is not possible to install complex runtime on this platforms. So there are no mechanism to transparently link a "modules" in runtime.
Hopefully, there will be a normal support of modules in C++17 standard. And Microsoft will provide a technology preview of modules in C++ in MSVC 2015 update 1.
Do I miss some fundamental understanding of C++ environement?
Yes, I propose you to read about compiling and linking in C/C++. This two things are often come together, but they are different.
First, that you should mind: code in C/C++ is splitted in two parts: declaration (.h files) and implementation (.cpp files). .CPP files are compiled into binaries. .H files just declares an interfaces.