说明如何在Mac下让clang++,qmake及QtCreator互动

stereoMatching 2013-02-09 12:17:05

//
// main.cpp
// yyyy
//
// Created by yyyy on 2/6/13.
// Copyright (c) 2013 yyyy. All rights reserved.
//

#include <functional>
#include <iostream>
#include <initializer_list>
#include <memory>
#include <string>
#include <vector>

template<typename T>
inline void print_comma_separated_list(T value)
{
std::cout<<value<<std::endl;
}

template<typename First,typename ... Rest>
void print_comma_separated_list(First first,Rest ... rest)
{
std::cout<<first<<",";
print_comma_separated_list(rest...);
}

constexpr int multiply_two(int a)
{
return a * 2;
}

void initial(std::initializer_list<int> l)
{
if(std::begin(l) == std::end(l)){

}
}

int main()
{

// insert code here...
std::cout << "Hello, World!"<<std::endl;

std::shared_ptr<int> shr = std::make_shared<int>(10);
std::cout<<*shr<<std::endl;

auto func = [](){ std::cout << "hahaha\n"; };
func();

std::vector<std::string> strs{"yahoo", "haha"};
for(auto const &data : strs){
std::cout<<data<<std::endl;
}

std::vector<std::string> strs2 = std::move(strs);
for(auto const &data : strs2){
std::cout<<data<<std::endl;
}

std::unique_ptr<int> A(new int(3));
std::cout<<*A<<", wahaha"<<std::endl;



print_comma_separated_list(32, "444", 34.564564, "lalamimilolipo");

return 0;
}


.pro file

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

LIBS += -stdlib=libc++

QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
QMAKE_LFLAGS += -mmacosx-version-min=10.7


如果clang++太旧了,可以用macport下载比较新的版本

port search clang //搜寻clang的版本
sudo port install [clang版本]

这原本是我发在
http://bbs.csdn.net/topics/390366089
这一帖上的问题,原本想直接在那一贴上说明我已经找到解答了
可是由于无法连续回答三次,我只好另外开个帖子

利用上面的解法,会遇到一个warning
ld: warning: directory not found for option '-F/Users/yyyy/Qt5.0.1/5.0.1/clang_64/qtbase/lib'
这个warning是Qt5的bug,就算不管他也不会有什么大碍的样子,希望下一版本的Qt可以修正过来
...全文
491 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
乔巴好萌 2013-02-12
  • 打赏
  • 举报
回复
当初据说是apple嫌gcc没有更贴近ios的体系结构,换言之,嫌gcc在底层对Objective-c不够优化。 因此,重新搞了一个clang。 这也解释了为什么ios比android更省电,相同的配置体验更流畅,因为都已经在编译器上进行优化了
引用 2 楼 stereoMatching 的回复:
我不晓得Qt在mac下使用clang的理由是否真如你所说 我当初的猜测是clang为mac下最普及的编译器 所以Qt才会选择他 clang发展的不错这点挺让人高兴的 gcc不再是一家独大的开源编译器 有竞争进步才会快 若非clang和llvm,gcc大概到现在还在 拥抱旧的代码并和linus一起极力贬低c++吧
stereoMatching 2013-02-10
  • 打赏
  • 举报
回复
我不晓得Qt在mac下使用clang的理由是否真如你所说 我当初的猜测是clang为mac下最普及的编译器 所以Qt才会选择他 clang发展的不错这点挺让人高兴的 gcc不再是一家独大的开源编译器 有竞争进步才会快 若非clang和llvm,gcc大概到现在还在 拥抱旧的代码并和linus一起极力贬低c++吧
乔巴好萌 2013-02-09
  • 打赏
  • 举报
回复
Qt使用clang估计是使用其一些特性,用于语法的自动补全 我没深入研究过clang 但是基于clang做语法前端自动补全的工具很多 如emacs+auto-complete-clang sublime Text基于clang的自动补全 但基于gcc的动态语法补全很少,像gccsense的还需要先建立索引 Qt的语法补全比较智能 应该是使用了clang的很多特性
========= Cppcheck ========= About The original name of this program is "C++check" but it was later changed to "cppcheck". Manual A manual is available online: http://cppcheck.sourceforge.net/manual.pdf Compiling Any C++11 compiler should work. For compilers with partial C++11 support it may work. If your compiler has the C++11 features that are available in Visual Studio 2010 then it will work. If nullptr is not supported by your compiler then this can be emulated using the header lib/cxx11emu.h. To build the GUI, you need Qt. When building the command line tool, PCRE is optional. It is used if you build with rules. There are multiple compilation choices: * qmake - cross platform build tool * cmake - cross platform build tool * Windows: Visual Studio * Windows: Qt Creator + mingw * gnu make * g++ 4.6 (or later) * clang++ qmake ===== You can use the gui/gui.pro file to build the GUI. cd gui qmake make Visual Studio ============= Use the cppcheck.sln file. The file is configured for Visual Studio 2013, but the platform toolset can be changed easily to older or newer versions. The solution contains platform targets for both x86 and x64. To compile with rules, select "Release-PCRE" or "Debug-PCRE" configuration. pcre.lib (pcre64.lib for x64 builds) and pcre.h are expected to be in /extlibs then. Qt Creator + mingw ================== The PCRE dll is needed to build the CLI. It can be downloaded here: http://software-download.name/pcre-library-windows/ gnu make ======== Simple build (no dependencies): make The recommended release build is: make SRCDIR=build CFGDIR=cfg HAVE_RULES=yes Flags: SRCDIR=build : Python is used to optimise cppcheck CFGDIR=cfg : Specify folder where .cfg files are found HAVE_RULES=yes : Enable rules (pcre is required if this is used) g++ (for experts) ================= If you just want to build Cppcheck without dependencies then you can use this command: g++ -o cppcheck -std=c++0x -include lib/cxx11emu.h -Iexternals/tinyxml -Ilib cli/*.cpp lib/*.cpp externals/tinyxml/*.cpp If you want to use --rule and --rule-file then dependencies are needed: g++ -o cppcheck -std=c++0x -include lib/cxx11emu.h -lpcre -DHAVE_RULES -Ilib -Iexternals/tinyxml cli/*.cpp lib/*.cpp externals/tinyxml/*.cpp mingw ===== The "LDFLAGS=-lshlwapi" is needed when building with mingw mingw32-make LDFLAGS=-lshlwapi other compilers/ide =================== 1. Create a empty project file / makefile. 2. Add all cpp files in the cppcheck cli and lib folders to the project file / makefile. 3. Compile. Cross compiling Win32 (CLI) version of Cppcheck in Linux sudo apt-get install mingw32 make CXX=i586-mingw32msvc-g++ LDFLAGS="-lshlwapi" mv cppcheck cppcheck.exe Webpage http://cppcheck.sourceforge.net/

16,203

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧