一、首先来编译VCF自带的例子Helloworld2(使用静态库)
cd c:\vcf-0.9.0\examples\helloworld2
mingw32-make -f makefile.gcc OPTION_DEBUG=0 OPTION_SHARED=0
然后提示错误如下:
..\..\lib/libApplicationKit_s.a(ApplicationKit_lib_DefaultTableCellItem.o):Defau
ltTableCellItem.cpp:(.text$_ZNSt8_Rb_treeIN3VCF13UnicodeStringESt4pairIKS1_NS0_4
FontEESt10_Select1stIS5_ESt4lessIS1_ESaIS5_EE9_M_insertEPSt18_Rb_tree_node_baseS
D_RKS5_[std::_Rb_treeF::Font>, std::_Select1st >, std:
:less, std::allocatorF::Font> > >::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std:
:pair const&)]+0xb5): undefined reference t
o `VCF::Font::Font(VCF::Font const&)'
collect2: ld returned 1 exit status
mingw32-make: *** [.\HelloWorld2_s.exe] Error 1
打开helloworld2\makefile.gcc文件
修改115行
$(CXX) -o $@ $(HELLOWORLD2_OBJECTS) $(LDFLAGS) $(__DEBUG_INFO) -mthreads -Wl,--enable-runtime-pseudo-reloc -L..\..\lib -Wl,--subsystem,windows -mwindows -lrpcrt4 -lodbc32 -lodbccp32 -lversion -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lcomctl32 -lws2_32 -lopengl32 -lglu32 $(____HelloWorld2_FOUNDATIONKIT_p) -l$(LIBAGG_FILENAME) -l$(ZLIB_FILENAME) -l$(LIBJPEG_FILENAME) -l$(LIBPNG_FILENAME) $(____HelloWorld2_GRAPHICSKIT_p) $(____HelloWorld2_APPLICATIONKIT_p)
为:
$(CXX) -o $@ $(HELLOWORLD2_OBJECTS) $(LDFLAGS) $(__DEBUG_INFO) -mthreads -Wl,--enable-runtime-pseudo-reloc -L..\..\lib -Wl,--subsystem,windows -mwindows $(____HelloWorld2_APPLICATIONKIT_p) $(____HelloWorld2_GRAPHICSKIT_p) $(____HelloWorld2_FOUNDATIONKIT_p)
-lrpcrt4 -lodbc32 -lodbccp32 -lversion -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lcomctl32 -lws2_32 -lopengl32 -lglu32 -l$(LIBAGG_FILENAME) -l$(ZLIB_FILENAME) -l$(LIBJPEG_FILENAME) -l$(LIBPNG_FILENAME)
注意不要换行,再编译,出现以下错误:
..\..\lib/libApplicationKit_s.a(ApplicationKit_lib_Win32Edit.o):Win32Edit.cpp:(.
text$_ZN3VCF24Win32RichEditOleCallback14QueryInterfaceERK5_GUIDPPv+0x27): undefi
ned reference to `IID_IRichEditOleCallback'
IID_IRichEditOleCallback是在richole.h头文件中定义的,但gcc好像没有将他链接到库中,所以我要自己来做
新建一个richole.cpp文件,内容如下:
#include
#include
#include
const GUID IID_IRichEditOle={};
const GUID IID_IRichEditOleCallback={};
然后编译他
g++ -o richole.o -c richole.cpp
ar r librichole.a richole.o
将librichole.a复制到c:\vcf-0.9.0\lib目录下
再修改makefile.gcc,在刚才那行尾添加-lrichole,再编译OK。
运行HelloWorld2_s.exe,看看效果吧(他需要mingwm10.dll运行时库,如果要编译脱离该库的程序,只需去掉-mthreads选项)
二、下面我们来自己手动编译
示例程序Helloworld.cpp:
#include "vcf/ApplicationKit/ApplicationKit.h"
using namespace VCF;
class HelloWorldApp : public Application {
public:
HelloWorldApp( int argc, char** argv ): Application(argc, argv) {
}
virtual bool initRunningApplication() {
Application::initRunningApplication();
Window* mainWindow = new Window();
setMainWindow( mainWindow );
mainWindow->setCaption( "Hello World" );
mainWindow->show();
return true;
}
};
int main(int argc, char *argv[])
{
Application* app = new HelloWorldApp( argc, argv );
Application::main();
return 0;
}
然后运行:
g++ -o helloworld.o -c -D_WIN32 -DWIN32 -D_WINDOWS -DVCF_MINGW HelloWorld.cpp
g++ -o helloworld.exe -Wl,--subsystem,windows -mwindows helloworld.o -lApplicationKit_s -lGraphicsKit_s -lFoundationKit_s -lrpc
rt4 -lversion -llibagg_s -lole32 -luuid -lcomctl32 -loleaut32 -lrichole
-DVCF_MINGW是必须的,不然会有很多的编译错误
这样编译会非常麻烦,如果将所有需要的库链接成一个库就方便多了,操作如下:
ar x libApplicationKit_s.a #将所有的目标文件扩展出来
ar r libFoundationKit_s.a *.o -lrichole -lrpcrt4 -lodbc32 -lodbccp32 -lversion -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lcomctl32 -lws2_32 -lopengl32 -lglu32 -llibAGG_s -lZLib_s -lLibJPEG_s -lLibPNG_s
再链接程序就方便多了:
g++ -o helloworld.exe -Wl,--subsystem,windows -mwindows helloworld.o -lApplicationKit_s -lGraphicsKit_s -lFoundationKit_s
阅读(2486) | 评论(0) | 转发(0) |