MinGW+Windows SDK的配置

clariones 2008-01-18 03:28:32
最近在开发一些Linux移植到Windows的东西,所以使用MinGW+Windows SDK来做开发平台。
发现必须使用MinGW的头文件,连接命令也要用gcc而不是ld,否则连"malloc, sprintf"这样的函数都报“unresolved”。
谁能告诉我MinGW+Windows SDK时,
1、如何配置编译选项才能正确使用Windows SDK的头文件而不是MinGW的?
2、如何配置连接选项,才能正确连接Windows SDK的lib库而不是MinGW下的lib*.a?
3、怎样才能使用ld而不是gcc正确连接目标文件?

看上去很简单,不过不一定。网上说过的若干办法我都试过,没什么效果。

谢谢
...全文
1641 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
岁月小龙 2012-09-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
1.Mingw根本就不能编译MS Win32 SDK中的东西.除非你有兴趣把出错的地方都修正了.当然,已经有人干这个事了.这个项目叫win32api,在Mingw里已经有了.如果遇到里面没有的API,你也可以手工添加.
2.Mingw应该可以正确使用SDK里的LAB文件,只是用的时候你要手工指明而已.不过win32api已经提供了它所支持的API的LIB文件,这个动作就不是很必要了.
3.用G……
[/Quote]

怎么手工添加呢?
melody1128 2008-01-25
  • 打赏
  • 举报
回复
For Linux-based PCs
The Windows installation of MinGW Developer Studio comes complete with MinGW, which includes a compiler and other tools for writing software.
MinGW stands for Minimal GNU for Windows, and provides tools that are already present on many GNU/Linux systems, so the Linux package does not include them, preferring to use the versions provided by your Linux distribution. However, this does mean that you need to use your distribution's package manager to satisfy some dependencies before you can start working with the tools. Firstly, MinGW Developer Studio will need some tools for building software: g++, make, ar, gdb. It's likely that you already have these tools, but if not, they're very common and will be easy to find amongst your distribution's packages. Secondly, MDS requires a library called GTK+ (of at least version 2.0) to be installed. It is likely to already be installed, but your package manager will help if not. With these packages installed, you can get started with MDS:

1) Go to the 'unix' directory on the CD.
2) Copy the directory tree 'tutorial' to the drive where you want to keep your work. You will need work space but nothing very large, by modern standards; a couple of hundred megabytes will be ample room for everything including the IDE and compiler.
3) In the MinGW directory on the CD is a file called 'mingw-devstudio_linux-2.06.tar.gz'. Copy this file to wherever you would like to install the IDE (it is probably most convenient to install it on the same drive as the tutorial directory), and then expand it with the command:

tar xvzf mingw-devstudio_linux-2.06.tar.gz

This will create a directory named MinGWStudio, which contains the
executable file, also called MinGWStudio. Running that file will start the IDE.
Compiling the fgw library
We now need to compile the fgw library. In order to do this, we must satisfy another dependency. The graphical part of the library depends on the X Window System, which will already be installed on your computer if you use a graphical desktop. However, since we need to compile some software to use the library, we need to ensure the various header files for the Xlib system are installed. When searching for an Xlib package, you need to install a version that includes the header files – these packages generally have a '-dev' or '-devel' tag in the name. If in doubt,
you need to find a package that contains a file called 'Xlib.h'.

With the Xlib system taken care of, the following instructions walk you through the compilation process.
1) Start a new project in MinGW Developer Studio called 'fgw' and make its type a 'Static Library'. Change the location to <location>/tutorial/source where <location> is the location of the tutorial directory tree.
2) Go to the Project menu –> Add to project –> Files.
3) Change the file type to C/C++ Source files
4) Change the 'look in' to 'source' (up one level in the directory tree)
5) Select all the files listed and click on Open.
6) Go to the Build menu and click and set the active configuration to Release (unless you specifically want to build a debug version of my library).
7) Go to the Build menu and click on Build. (note that if you have already recompiled my library, you will need to use 'clean' first to remove the files created previously).

The newly created libfgw.a will now be found in the Release (or Debug if you opted for that) subdirectory of fgw: <location>/tutorial/source/fgw/Release. Copy it to <location>/tutorial/fgw_headers.

注:这里的fgw_headers是自己的库
  • 打赏
  • 举报
回复
你下一个codeblock或者devcpp
都是集成了mingw的相关工具,直接就能写winSDK的东西.
clariones 2008-01-25
  • 打赏
  • 举报
回复
Thanks redleaves , 我验证一下,准备结帖了
redleaves 2008-01-23
  • 打赏
  • 举报
回复 1
1.Mingw根本就不能编译MS Win32 SDK中的东西.除非你有兴趣把出错的地方都修正了.当然,已经有人干这个事了.这个项目叫win32api,在Mingw里已经有了.如果遇到里面没有的API,你也可以手工添加.
2.Mingw应该可以正确使用SDK里的LAB文件,只是用的时候你要手工指明而已.不过win32api已经提供了它所支持的API的LIB文件,这个动作就不是很必要了.
3.用GCC做连接和用LD是一个效果,只不过GCC会默认连接一些库,如果你非要手工用LD连接,那你必须要连接那几个要用的.a以及相应的.o.要注意的是,这里的.o是指LAB里的CRT入口的.o文件.
小小的王药师 2008-01-22
  • 打赏
  • 举报
回复
MinGW本身就有windows SDK的头文件的吧?
星羽 2008-01-19
  • 打赏
  • 举报
回复
楼上发错了,不要见怪阿,哈哈
星羽 2008-01-19
  • 打赏
  • 举报
回复
在KDevelop主窗口的右侧有一个Automake Manager标签。点击该标签,就可以看到本工程源文件所在的文件夹以及各文件。在列有文件的那个窗口上方有工具条,其中就是用来添加文件的。添加文件有两种方式,一种是链接(link)方式,另一种是复制(copy)方式。
1、安装qt sdk 我装的是qt 5.3 msvc版32位,内置了qt creator,直接用windows带的msvc编译器。 2.安装opencv 我装的是opencv2.4.9 for windows,解压到D盘根目录下了。 注意opencv for windows解压后就有个build文件夹,说明是用msvc编译器编译好的,我们的qt用的是msvc编译器的话就可以直接导入链接库和头文件了,不需要网上那些人所说的要搞minGW和cmake编译,如果你装的qt是minGW版的就需要用cmake重新编译一遍opencv,相关教程一搜一大把。 3.在qt creator中建一个标准的控制台C++工程项目。 随便建哪种项目都是可以的,这里为了方便直接建立最简单的C++控制台项目。 4.配置opencv的环境变量(此步貌似可省,但是配个环境变量总是保险的) 在另一篇博客里讲过http://blog.csdn.net/u012234115/article/details/38612977 5.修改工程的pro文件。 要包含头文件目录和静态连接库目录,在里面加入 INCLUDEPATH+=d:/opencv/build/include/opencv \ d:/opencv/build/include/opencv2 \ d:/opencv/build/include LIBS+=D:\opencv\build\x86\vc12\lib\opencv_ml249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_calib3d249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_contrib249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_core249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_features2d249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_flann249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_gpu249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_highgui249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_imgproc249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_legacy249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_objdetect249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_ts249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_video249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_nonfree249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_ocl249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_photo249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_stitching249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_superres249d.lib LIBS+=D:\opencv\build\x86\vc12\lib\opencv_videostab249d.lib 以上加入的是debug版本的库,如果要release版本的就把后面的d去掉。其中/和\这两种斜杠都可以表示路径,但是不同路径换行分隔必须用\,INCLUDEPATH和LIBS等都可以一次加多条或者一次加一条,注意格式 加完了注意要qmake一下。
C 和 C++ 语言都是世界上最流行且使用最普遍的编程语言, 因此 Eclipse 平台(Eclipse Platform)提供对 C/C++ 开发的支持一点都不足为奇。 因为 Eclipse 平台只是用于开发者工具的一个框架,它不直接支持 C/C++;它使用外部插件来提供支持。 本文将向您演示如何使用 CDT — 用于 C/C++ 开发的一组插件。CDT 项目(有关链接, 请参阅本文后面的 参考资料一节)致力于为 Eclipse 平台提供功能完全的 C/C++ 集成开发环境(Integrated Development Environment,IDE)。 虽然该项目的重点是 Linux,但它在可使用 GNU 开发者工具的所有环境(包括 Win32(Win 95/98/Me/NT/2000/XP)、QNX Neutrino 和 Solaris 平台)中都能工作。 CDT 是完全用 Java 实现的开放源码项目(根据 Common Public License 特许的),它作为 Eclipse SDK 平台的一组插件。这些插件将 C/C++ 透视图添加到 Eclipse 工作台(Workbench)中, 现在后者可以用许多视图和向导以及高级编辑和调试支持来支持 C/C++ 开发。 由于其复杂性,CDT 被分成几个组件,它们都采用独立插件的形式。 每个组件都作为一个独立自主的项目进行运作,有它自己的一组提交者、错误类别和邮件列表。 但是,所有插件都是 CDT 正常工作所必需的。 下面是 CDT 插件/组件的完整列表: 主 CDT 插件(Primary CDT plug-in)是“框架”CDT 插件。 CDT 功能 Eclipse(CDT Feature Eclipse)是 CDT 功能组件(Feature Component)。 CDT 核心(CDT Core)提供了核心模型(Core Model)、CDOM 和核心组件(Core Component)。 CDT UI是核心 UI、视图、编辑器和向导。 CDT 启动(CDT Launch)为诸如编译器和调试器之类的外部工具提供了启动机制。 CDT 调试核心(CDT Debug Core)提供了调试功能。 CDT 调试 UI(CDT Debug UI)为 CDT 调试编辑器、视图和向导提供了用户界面。 CDT 调试 MI(CDT Debug MI)是用于与 MI 兼容的调试器的应用程序连接器。 现在,让我们研究一下如何在实际应用程序中使用这些组件。图 1 显示了 Eclipse 中的 C/C++ 项目: 图 1. 在带有 CDT 插件的 Eclipse 中编辑 C/C++ 项目 安装和运行 CDT 在下载和安装 CDT 之前,首先必需确保 GNU C 编译器(GNU C compiler,GCC)以及所有附带的工具(make、binutil 和 GDB)都是可用的。 如果正在运行 Linux,只要通过使用适用于您分发版的软件包管理器来安装开发软件包。 在 Windows平台上,将需要安装 Cygwin 工具箱(请参阅 参考资料以获得链接)。Cygwin 是用于 Windows 的类 UNIX 环境,它包括 GCC 移植以及所有必需的开发工具,包括 automake 和 GNU 调试器(GNU Debugger,GDB)。Cygwin 是在 cygwin1.dll 库基础上构建的。Cygwin 的备用解决方案是 Minimalist GNU for WindowsMinGW)(请参阅 参考资料以获得链接)。 该工具是一组可免费获取、自由分发的特定于 Windows 的头文件和导入库,这些头文件和导入库与 GNU 工具集(它们允许您生成不依赖于任何第三方 DLL 的本机 Windows 程序)结合在一起。 如果您想要创建与 POSIX 兼容的 Windows 应用程序,那么 MinGW 是最佳选择。MinGW 甚至可以在 Cygwin 安装之上工作。 Solaris和 QNX要求您从因特网下载并安装其特定的 GCC、GNU Make binutils 和 GDB 移植(请参阅 参考资料以获得链接)。 假设您安装了适当的 Java SDK/JRE 和 Eclipse 平台 SDK,并且它们都正常运行。CDT 以两种“方式”可用:稳定的发行版和试运行版(nightly build)。 试运行版未经完全测试,但它们提供了更多的功能并改正了当前错误。 安装之前,请检查磁盘上是否存在先前版本的 CDT,如果存在,请确保完全除去它。 因为 CDT 没有可用的卸载程序,所以需要手工除去它。 为了检查先前版本是否存在,转至 CDT 插件所驻留的目录: eclipse/plugins 。 接着,除

69,374

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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