跳到主要內容

發表文章

目前顯示的是有「cmake」標籤的文章

Getting Started with Google Test and CMake on Windows

Getting Started with Google Test and CMake on Windows Versions Windows 7 MSVC 11 (Visual Studio 2012) CMake 3.0 gtest 1.7.0 Google Test Assume we placed unzipped gtest source in %GTEST_ROOT% . To get gtest-1.7.0 compiled with MSVC11, edit %GTEST_ROOT%\cmake\internal_utils.cmake . macro ( fix_default_compiler_settings_ ) $ if ( MSVC ) $ add_definitions ( - D_VARIADIC_MAX = 10 ) # Add this line # . . . endif ( ) endmacro ( ) Note : You won’t need the workaround with MSVC12, or VS2013 (I envy you). Open up “Developer Command Prompt for VS2012” (yeah, I LOVE cmdline) and type: # Compile cd %GTEST_ROOT% mkdir build cd build cmake .. -G "NMake Makefiles" # Install with prefix "c:\opt" ( change it to whatever you like ) mkdir c:\opt\lib mkdir c:\opt\include xcopy *.lib c:\opt\lib cd .. xcopy include\gtest c:\opt\include\ Note : I actually did files/dirs copying in cygwin and welcome feedback for...

boost::python - 從 C C++ 中呼叫 Python 函式

boost::python - 從 C C++ 中呼叫 Python 函式 背景 如果對 callback 已經很熟悉的可以跳過這段;不少函式庫的 API 會接收 callback 或者是 action 函式,如下 // File: callback.hpp # ifndef CALLBACK_HPP_ # define CALLBACK_HPP_ // void* 為使用者傳入的 context, val 是函式庫指定的值 typedef void ( raw_cb_t ) ( void * ctx , int val ) ; void libfunc ( raw_cb_t * cb , void * ctx ) ; # endif 這裡的 raw_cb_t cb 就是 callback/action 函式,作為一個參數傳遞給 libfunc ,由它決定何時呼叫,如下 // File: callback.cpp # include "callback.hpp" void libfunc ( raw_cb_t * cb , void * ctx ) { for ( int i = 0 ; i < 10 ; i ++ ) { cb ( ctx , i ) ; } } 使用 libfunc 這個 API 的方式在 C/C++ 裡面可以是 // File: main.cpp # include <iostream> # include "callback.hpp" void handler ( void * ctx , int val ) { int * sum = static_cast < int * > ( ctx ) ; std : : cout << ( * sum ) + = val << std : : endl ; } int main ( void ) { int sum = 0 ; libfunc ( & handler , ...