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正确连接目标文件?

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

谢谢
...全文
1903 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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)方式。

70,024

社区成员

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

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