build a c++ program with makefile in windows - c++

I wrote a little c++ program with visual studio.
I have to build that program with a shell script. For that I installed cygwin. How can I build a program, that uses an environment variable for the boost-library?

Install boost from http://www.boost.org/users/download/
I'm not sure of the system that you use to compile C++ but thing is for sure, you need to create a makefile for your program.
After makefile is created, add to the flags the following:
-lboost_system -lboost_locale
Good luck!

Related

How can i use neovim and coc.nvim for develop windows c++ apps on linux

I develop c++ apps on linux and i use neovim with coc.nvim and coc-clangd plugins.
I want to develop an app for windows but i comfort with linux and neovim so i want to use them for it. But i get some include errors with some windows headers (etc. "windows.h").
I use linux only for writing the code and i'll compile the program on windows. How can i prevent this errors and use windows headers with coc.nvim?
i'll compile the program on windows
You can cross-compile it from Linux. It's only marginally more difficult than getting the code completion to work.
Get the standard library headers (and libraries, if you want to cross-compile) from MinGW.
Your package manager might have those, or you can get them from https://winlibs.com/.
I prefer getting those from MSYS2, and made scripts to automate this (since MSYS2 is otherwise Windows-only):
git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2/
make install _gcc
Figure out the Clang flags needed to cross-compile.
Unlike GCC, which for every target platform requires a separate compiler distribution, Clang is inherently a cross-compiler. You only need a single Clang distribution to compile for any supported platform.
Download Clang from your package manager, and point it to the freshly downloaded headers and libraries.
Following flags work for me: clang++-14 1.cpp --target=x86_64-w64-mingw32 --sysroot=/path/to/quasi-msys2/root/mingw64 -fuse-ld=lld-14 -pthread -stdlib=libstdc++ -femulated-tls -rtlib=libgcc.
--target and --sysroot are crucial. The latter needs to point to the files you've downloaded. The remaining flags are less important.
Running this should produce a.exe, runnable with wine a.exe.
Feed the same flags to Clangd.
There are several ways to set compiler flags for Clangd.
The easiest one is to create a file named compile_flags.txt in your project directory, and put the flags into it, one per line:
--target=x86_64-w64-mingw32
--sysroot=/path/to/quasi-msys2/root/mingw64
-fuse-ld=lld-14
-pthread
-stdlib=libstdc++
-femulated-tls
-rtlib=libgcc
Then Clangd should do the right thing for any source files in this directory.
Apparently, my Quasi-MSYS2 can somewhat automate this.
After running the commands above (make install _gcc and others), run make env/shell.sh, and run your editor from this shell.
Replace compiler_flags.txt with compiler_commands.json with following contents:
[
{
"directory": "/your/sources",
"file": "/your/sources/1.cpp",
"command": "win-clang++ 1.cpp"
}
]
Where win-clang++ is a Clang wrapper I ship, which automatically adds the flags I listed above.
Configure your editor to add following flag to Clangd: --query-driver=/path/to/win-clang++ (use which win-clang++ from quasi-msys2 shell to get the full path).
This makes Clangd obtain the right flags automatically from this wrapper.
You can't use windows.h while you're compiling a Linux native application. If want to make your application platform ready and you're using some kind of OS native cals, then you have to probably use defines like #if _WIN32/__linux__ and so on. At the end, you can cross-compile your application to Windows while you're running on Linux as well.

I built a C++ program on Windows, how can I compile an executable for MacOS?

I have built a little C++ program on Windows, and I'd like to share it with some people, but they are on MacOS. What tools can I use to compile an executable (like .exe for Windows) and share the project to them? If needed, I have a MacOS VM.
Build your sources with Xcode. Or try to run .exe with WINE (https://www.winehq.org/)

How to know the command line arugments to build a project that was coded in eclipse

I have a project that I coded in Eclipse, now I need to compile it and run using the terminal. The project has some additional libraries that were added to the linker.
e.g.
g++ then what?
How can I know that command line arguments that I need to run it through the terminal?
The project was coded in c++ using eclipse Luna on a linux machine.
Thanks
You could always try
g++ -std=c++0x your_file_name.cpp -o desired_output_name

Debugging an .out object, compiled with cmake, using GDB

I have a large C++ project that is compiled using a cmake file (that for the moment I couldn't hope to recreate/compile using g++), and even though I run it in debug mode, i.e. using in terminal
cmake -DCMAKE_BUILD_TYPE=Debug ..
I don't get any .out file I can run GDB with... what am I doing wrong? New to C++ development. Any advice would be appreciated. Running VSCode on Ubuntu.
My main goal is to try and find performance bottlenecks in the program, for which I've found valgrind/gdb/gprof should help? Any tips?
Cmake isn't compiler, it creates makefiles for your platform, then you have to use compiler to build project( basically make -j for gcc, where j amount of cores, or nmake for msvc compiler)

How to make exe in Qt?

I'm starting to learn Qt and I'm stuck on particular step, which is: I cannot create executable file. My steps are as follows:
Creation of *.cpp
In console typing qmake -project (this creates .pro file)
In console typing qmake -makefile (now I have makefile + some other files)
I'm trying to create .exe by typing qmake but this isn't working. I've also tried nmake, bmake and make but no results.
Any help will be appreciated.
Thank you.
It depends on what compiler you are using. If you're using GCC or MinGW, type make. If make cannot be found, either it is not installed, or it's not in your path (more likely to be the case). Try using the command prompt shortcut Qt provides you (if on Windows). If on a POSIX-based/-like system, make should exist. If it doesn't, then it depends if you're on a Mac or on Linux/BSD. On a Mac, make should come with the developer tools, which is one of the last CDs in the OS X installation CDs. If you're on Linux, use your package manager. rpm for Red Hat based systems, apt for Debian based systems, and so on. Google about them.
If you're using Visual C++ and nmake doesn't work, it could mean that nmake isn't on your path. Try using the Visual C++ command prompt instead of the normal command prompt (should be somewhere in your start menu).
It would be more helpful if you could mention how you installed Qt, and on what system.
I believe you need to do something like:
qmake -o Makefile hello.pro
Then type make or nmake depending on the compiler you use.