How to compile code that have qt6 in mingw64? - windows

I try to use mingw-w64 to compile my code that have qt6 library. but, i get long compile error. for testing my environtment is work. I just try to check qt version.
#include <QtCore>
#include <iostream>
int main() {
std::cout << "Qt version: " << qVersion() << std::endl;
}
I installed everything i need with pacman in single line command
pacman -S --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-qt6
i think library alraedy settle.
now i try to compile the code with this command
g++ version.cpp -o version -I/mingw64/include/qt6/QtCore
-I/mingw64/include/qt6 -I/mingw64/lib/qt6 -lQt6Core -fPIC
i get long failed error compile.

Related

macOS 10.14: Cannot find stdio.h

I am trying to run the following hello world program:
#include <stdio.h>
int main(){
printf("Hello, world!\n");
return 0;
}
With my system's default C compiler located in /usr/bin/gcc, that works as expected. But when I am using the compiler I installed, GCC version 6.4, located in $HOME/usr/bin/, I get the following error:
$ gcc main.cc
main.c:1:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
Any idea on how to fix it? I've tried xcode-select --install/reset. Also, at first, compilation was failing with the system's gcc but I fixed it by creating the /usr/include directory. However, I need to use the compiler I've installed.

Compiling error with g++ 4.9 on OSX Yosemite

Recently I installed the new version of gcc (4.9) on OSX Yosemite, following the steps that I found on:
https://wiki.helsinki.fi/display/HUGG/Installing+the+GNU+compilers+on+Mac+OS+X
But when I try to compile a simple "Hello World" program, the compiler print the next:
fatal error: iostream: No such file or directory
compilation terminated.
It seems to be a easy problem to solve, but I'm new using this OS. So I don't want to mess it up.
Thank you!.
The code is just a "Hello World" :
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
Then I complile with g++ on Terminal like this: g++ hw.cpp -o hw.o
The the result is: fatal error: iostream: No such file or directory
You are probably using gcc instead of g++, try doing the following:
g++ your_source_file.cpp -std=c++11

How do you compile C++ programs that include LLVM API headers?

I'm trying to use the C++ compiler to compile the following program:
#include <stdio.h>
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/IR/Module.h"
int main( int argc, char* argv[] )
{
if( argc < 2 )
llvm::errs() << "Expected an argument - IR file name\n";
llvm::LLVMContext &context = llvm::getGlobalContext();
llvm::SMDiagnostic err;
llvm::Module* module = llvm::ParseIRFile( argv[1], err, context );
if( !mod )
{
err.print( argv[0], errs() );
return 1;
}
return 0;
}
I'm trying to compile the program using the following command:
clang++ main.cpp -o main
However, when I compile, I'm getting the following compile error:
main.cpp:2:10: fatal error: 'llvm/IR/LLVMContext.h' file not found
#include "llvm/IR/LLVMContext.h"
^
1 error generated.
In this case, I'm not exactly sure how to link the LLVM API headers when compiling main.cpp with Clang.
Any help would be greatly appreciated.
You can use the following command:
g++ -std=c++11 main.cpp `llvm-config --system-libs --cppflags --ldflags --libs core` -o main
Where --libs and --system-libs flags are used for linking and --cppflags takes care of include paths.
Thank You
You need LLVM checked out or installed somewhere on your system. You can download a binary release (with headers and libraries you can build against) as explained here: http://llvm.org/releases/download.html#3.5
You can also check out LLVM from its SVN repository as explained here: http://llvm.org/docs/GettingStarted.html#checkout
Once you do that, I recommend looking at the llvm-clang-samples repository that comes with a Makefiles showing how to build sample programs vs. an up-to-date LLVM.

Why does clang++ lack forward list?

I wrote up a simple C++ program that relies on forward_list like
#include <forward_list>
#include <iostream>
int main() {
std::forward_list<int> my_list;
my_list.push_front(3);
std::cout << my_list.top() << std::endl;
return 0;
}
However, when I compile this program on my Mac with clang++ my_program.cpp -std=c++11 -o my_program, I get this error:
my_program.cpp:1:14: fatal error: 'forward_list' file not found
#include <forward_list>
^
1 error generated.
Why can't clang find forward_list? Other C++11 features are working. For instance, the auto keyword works, albeit a warning appears that tells me that auto is a C++11 feature.
By default clang++ uses an older gcc-4.2 std library which has no C++11 support. You can tell clang to use a C++11-aware std::lib with the command -stdlib=libc++. libc++ has <forward_list>.

Programs with Boost Dependency Fail to Compile in Qt Creator

I get undefined reference errors to various things in the boost:: namespace if I attempt to compile programs that use any parts of Boost Libraries in Qt Creator 2.5.2. At first I thought it's because I was mixing static Boost libraries with shared Qt libraries, so I recompiled Boost with link=shared runtime-link=shared build option, but the problem remains. I then started a Non-Qt, Plain C++ project that consists of nothing more than a main.cpp containing a slightly modified Boost test program:
// main.cpp, cin-less version of
// http://www.boost.org/doc/libs/1_51_0/more/getting_started/windows.html#test-your-program
#include <iostream>
#include <string>
#include <boost/regex.hpp>
int main() {
std::string headerLines = "To: George Shmidlap\n" \
"From: Rita Marlowe\n" \
"Subject: Will Success Spoil Rock Hunter?\n" \
"---\n" \
"See subject.\n";
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
boost::smatch matches;
std::string::iterator newLinePos = std::find(headerLines.begin(), headerLines.end(), '\n');
std::string::iterator startPos = headerLines.begin();
while(newLinePos != headerLines.end()) {
if (boost::regex_match(std::string(startPos, newLinePos++), matches, pat)) {
std::cout << "\nRegex Match: " << matches[2];
}
startPos = newLinePos;
newLinePos = std::find(startPos, headerLines.end(), '\n');
}
char temp[3];
std::cin.getline(temp, 2);
return 0;
}
Project file:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
Debug {
LIBS += -lboost_regex-mgw46-mt-d-1_51
}
release {
LIBS += -lboost_regex-mgw46-mt-1_51
}
Compiling the above project from within Qt Creator, or using mingw32-make in command line, gives:
E:\BoostTest-483-MinGW_Debug\debug\main.o:-1: In function `ZN5boost13match_resultsIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS5_EEEE17raise_logic_errorEv':
c:\tdm-mingw32\include\boost\regex\v4\match_results.hpp:562: error: undefined reference to `boost::throw_exception(std::exception const&)'
E:\BoostTest-483-MinGW_Debug\debug\main.o:-1: In function `ZN5boost9re_detail12perl_matcherIN9__gnu_cxx17__normal_iteratorIPKcSsEESaINS_9sub_matchIS6_EEENS_12regex_traitsIcNS_16cpp_regex_traitsIcEEEEE14construct_initERKNS_11basic_regexIcSD_EENS_15regex_constants12_match_flagsE':
c:\tdm-mingw32\include\boost\regex\v4\perl_matcher_common.hpp:55: error: undefined reference to `boost::throw_exception(std::exception const&)'
[etc...]
Compiling main.cpp from command line, without Qt Creator or mingw32-make, works just fine:
E:\BoostTest>g++ -s -O3 main.cpp -o main.exe -lboost_regex-mgw46-mt-1_51
E:\BoostTest>main.exe
Regex Match: Will Success Spoil Rock Hunter?
E:\BoostTest>g++ -s -O3 main.cpp -o main-dbg.exe -lboost_regex-mgw46-mt-d-1_51
E:\BoostTest>main-dbg.exe
Regex Match: Will Success Spoil Rock Hunter?
Tested with:
TDM-MinGW32 (MinGW 4.6.1)
My own builds of MinGW:
MinGW 4.6.3 with dwarf2 exceptions handling
MinGW 4.6.3 with SJLJ exceptions handling
Boost Libraries 1.51.0 (built from source with each of the above compiler builds, static and shared libraries)
Qt Framework 4.8.3 for MinGW, precompiled binaries.
Qt Creator 2.5.2 for Windows.
I've checked Qmake's makescpecs configuration files, among other things, but still cannot figure out the root of the problem. Any ideas?
This is most likely far too late to help you, but I've just had to figure this one out today. I too am using mingw32 and Qt and had the same undefined reference.
I first resolved it by adding the following in `some file', based on another StackOverflow question:
namespace boost
{
void throw_exception(std::exception const &e) { assert(false); }
}
However I actually wanted to throw an exception, so changed the assert(false); to a throw e;. That immediately threw up the compile error:
error: exception handling disabled, use -fexceptions to enable
...which gives a clue.
The trick turned out to be adding CONFIG += exceptions (along with console so cout/printf etc. actually do anything, that was a real pain!) to my qmake file. I have no idea what is really going on here, maybe most Linux distros add something special to the qmake spec files or whatever.

Resources