TAG

首都機能移轉 (2) 歌詞 (2) 靠北文 (40) 戲言 (30) 糟糕 (7) ACG (23) Assembly (2) Boost (2) C (31) C++ (69) CMake (4) CSIE (67) Debian (34) Design_Pattern (2) Django (1) Eclipse (1) en_US (13) FFmpeg (3) FoolproofProject (26) FreeBSD (2) Git (4) GNU_Linux (65) IDE (5) Java (11) JavaScript (19) KDE (15) Khopper (16) KomiX (3) Kubuntu (18) Life (1) Lighttpd (2) Mac_OS_X (2) Opera (1) PHP (2) PicKing (2) Programing (21) Prolog (1) Python (7) QSnapshot (2) Qt (30) Qt_Jambi (1) Regular_Expression (1) Shell_Script (7) Talk (98) VirtualBox (7) Visual_Studio (13) Windows (18) zh_TW (36)
顯示具有 Visual_Studio 標籤的文章。 顯示所有文章
顯示具有 Visual_Studio 標籤的文章。 顯示所有文章

2012年8月2日 星期四

CMake: grouping sources by directory

function(group_sources root)
  function(__group_sources__ root prefix)
    file(GLOB entries RELATIVE "${root}" "${root}/*")
    foreach(entry ${entries})
      set(abspath "${root}/${entry}")
      if(IS_DIRECTORY "${abspath}")
        __group_sources__("${abspath}" "${prefix}/${entry}")
      else()
        list(APPEND group "${abspath}")
      endif()
    endforeach()
    string(REPLACE "/" "\\" prefix "${prefix}")
    source_group("${prefix}" FILES ${group})
  endfunction()

  get_filename_component(prefix "${root}" NAME)
  __group_sources__("${root}" "${prefix}")
endfunction()
Usage:
group_sources("${CMAKE_SOURCE_DIR}/src")
group_sources("${CMAKE_SOURCE_DIR}/include")
Note this function only creates filters in project, you still need to add source files by ADD_EXECUTABLE or ADD_LIBRARY commands. For more complete example, see this gist.

2011年4月9日 星期六

Lambda expression issue in VC10

class A {
public:
    A() {
        ( [&](){
            A::dummy; // VC10 compile error
        } )();
    }
private:
    static const int dummy = 0;
};
我也不知道怎麼解釋, 看起來是它搞混了實體存取和全域存取, 也就是說它不知道該不該自動補完成 this->A::dummy. 但如果使用 namespace 強制修飾成 ::A::dummy, 或是不使用 wildcard capture 就不會有問題.

2011年2月24日 星期四

Nested capturing in lambda expression

其實這是早已踩過的 bug, 單純留著當紀錄.
int i = 0;
( [&i]() {
    // capture once
    ++i;
    ( [&i]() {
        // capture twice
        ++i;
    } )();
} )();
std::cout << i << std::endl; // 2
來猜猜看上述程式用哪個 compiler 會出錯?

2011年2月2日 星期三

Lambda binding issue in VC10

VC10 的 lambda expression 的 bug 還真多 ... 這應該是我第三次踩到相關的 bug 了吧。
auto f( std::bind( []( int a, int b )->int {
    return a + b;
}, std::placeholders::_1, 2 ) );

f( 1 ); // returns 3

2010年11月11日 星期四

Qt 4.7.1 introduced -mp configuration

在這一篇所針對的是 Qt 4.7.0, 在 Qt 4.7.1 發佈後, 發現多了 -mp 的選項, 顧名思義, 加上之後它就會針對 msvc 開啟 /MP 參數. 在此統整一下我用的參數:
@echo off

SET PREFIX=Z:\Qt\4.7.1

configure ^
    -opensource ^
    -debug-and-release ^
    -mp ^
    -ltcg ^
    -fast ^
    -no-qt3support ^
    -no-dsp ^
    -no-vcproj ^
    -prefix %PREFIX% ^
    -nomake examples ^
    -nomake demos ^
    -nomake translations
MKDIR %PREFIX%\mkspecs
XCOPY /E /K mkspecs\* %PREFIX%\mkspecs
nmake
nmake install
nmake clean

2010年10月11日 星期一

Build Qt with Visual C++ 2010

在開始前要特別一提的是在 configure -help 未提及的參數:
-prefix <path>
指定編譯完成後的安裝路徑,nmake install 時會安裝到這個路徑。
-nomake <libs|tools|examples|demos|docs|translations>
可以指定哪部分不需要編譯。要注意的是如果要關掉多個模組須分開指定。
為了讓編譯程序能夠加快,我對 mkspecs 做了一點手腳。找到 mkspecs\win32-msvc2010\qmake.conf,修改:
-QMAKE_CFLAGS            = -nologo -Zm200 -Zc:wchar_t-
+QMAKE_CFLAGS            = -nologo -Zm200 -Zc:wchar_t- -MP3
-QMAKE_CFLAGS_RELEASE    = -O2 -MD
+QMAKE_CFLAGS_RELEASE    = -Ox -MD
提高最佳化參數,並啟動多重編譯。另外有點白爛的是,在編譯階段它會去安裝路徑找 mkspecs,問題是根本還沒進入安裝階段,資料夾內當然是空空如也;為此你必須手動把 mkspecs 從原本的資料夾整個複製到安裝路徑裡。

2010年5月22日 星期六

Templates needs no "__dllspec"

同之前提到的, Visual C++ 要做 export/import symbol 的動作才能連結 dll, 但是 template classes 和 functions 是不需要的 ... 原因很單純, 就是 template 在 Visual C++ 是原地展開的, 不需要再額外做 symbol 的定義[?].

2010年2月15日 星期一

Create source groups in Visual C++ solutions with CMake

使用 qmake 時,Visual C++ 的方案會自動把產生的檔案(e.g.: ui_*.h, moc_*.cpp ... etc.)歸類到 Generated Files,讓原始碼樹看起來比較清爽。但是 CMake 不會幫你做這件事,專案一大就會讓這些不必修改的檔案佔滿整個專案。
但是 CMake 其實是可以做到的,使用 SOURCE_GROUP 巨集就可以建造一個群組,把原始碼組織起來。過濾的方式有二:使用 regular expression,或是直接指明檔案路徑。以下是範例。
# 明指 moc, rcc, uic, qm 檔案為 Generated Files
source_group("Generated Files" FILES ${MOC_SOURCES} ${RCC_RESOURCES} ${UIC_HEADERS} ${QM_FILES})
# 使用 RE 把資源檔找出來
source_group("Resource Files" REGULAR_EXPRESSION .*\\.rc)
# 使用 RE 把 Designer forms 歸類在 Form Files
source_group("Form Files" REGULAR_EXPRESSION .*\\.ui)
注意 regular expression 要跳出 \。

2009年4月15日 星期三

Export DLL symbols to LIB

用 gcc 如果要發佈成 dll,只要編譯器加點選項,就可以發佈給別人連結了。但是 Visual C++ 卻要在每個 symbol 上加上關鍵字 __declspec(dllexport) 才會匯出到 lib,然後才能連結。
__declspec(dllexport) void blah();
class __declspec(dllexport) Blah {};
不管怎麼說,微軟的確是這方面的天才。

2008年8月18日 星期一

部置Visual C++程式

翻成"部署"還真是怪怪的....
我看就很麻煩,而且還失敗很多次....果然是DLL hell。