编译语言基础 [英] Compiled languages basics

查看:81
本文介绍了编译语言基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问有人可以向我解释一些关于使用C语言的基本事情吗?特别是在Windows上?


  1. 如果我想使用其他图书馆,我需要从图书馆?头文件.h和..?


  2. .dll和.dll.a有什么区别? .dll和.lib? .dll和.exe?什么是.def?


  3. 图书馆是如何编译的?我的意思是,是否可以在Windows上使用由MinGW编译的C代码中的VC编译的C ++库?


  4. 要使用另一个库,什么是首选方式?有一些只提供源代码或.dll的库 - 如何使用这样的库?LoadLibrary()或者#include <?p

  5. 每次重建项目时,是否必须重新编译?


  6. 如何创建一个大的.exe?这被称为静态链接?


  7. 如何将一些随机文件包含到.exe中?说一个程序图标或启动歌曲?


  8. 如何将我的巨大的.c分割成较小的?我需要为每个部分创建一个头文件,然后我将其添加到WinMain()或main()的部分中。


  9. 如果有库这需要另一个库,是否可以将这两个组合到一个文件?说,python26.dll需要msvcr90.dll和Microsoft.VC90.CRT.manifest


  10. 如果我不释放以前分配的内存会发生什么?如果程序(进程)死亡,这会被清理吗?


那么这么多问题?感谢每一个信息!

解决方案


1:如果我想使用一些其他库,我需要从图书馆吗?头文件.h和..?


...,通常是一个 *。lib 文件,您作为参数传递给您的链接器。


2:.dll和.dll有什么区别?一个。? .dll和.lib? .dll和.exe?什么是.def?


这可能很有用:静态库,动态库,DLL,入口点,标题...如何摆脱这个活着?


3:图书馆如何编制是否重要?我的意思是,是否可以在Windows上使用由MinGW编译的C代码中的VC编译的C ++库?


是的,这很重要。对于编译器之间的互操作,通常的方式是使用C风格(不是C ++风格)的API,具有明确的参数传递约定(例如 __ stdcall ),或使用'COM'接口。


4:要使用另一个库,最好的方法是什么? LoadLibrary()或#include <?>?


#include 编译器(例如,它可以编译到库的调用);和 LoadLibrary (或使用 *。lib 文件)用于运行时链接器/加载器(以便它可以将这些库方法的实际地址替换为您的代码):即您需要两者。


5:有一些库只提供源代码或.dll - 如何使用这样的库?每次重建项目时,是否必须重新编译?


如果只是源码,那么可以将该源(一次)编译成一个图书馆,然后(当你建立你的项目)链接到那个库(没有重新编译库)。


6:我如何创建一个大的.exe?这是所谓的静态连接吗?


是的,编译所有内容并将其全部传递给链接器。


7:如何将一些随机文件包含到.exe中?说一个程序图标或启动歌曲?


定义在Windows特定的资源文件中,由'资源编译器'。


8:如何将我的巨大的.c分成较小的?我需要为每个部分创建一个头文件,然后我将其添加到WinMain()或main()的部分中。


是的。


9:如果有一个库需要另一个库,是否可以将这两个组合成一个文件?说,python26.dll需要msvcr90.dll和Microsoft.VC90.CRT.manifest


我不明白你的问题/示例。


10:如果我不释放以前分配的内存,会发生什么?如果程序(进程)死亡,这将被清理?


是的。


please, could someone explain to me a few basic things about working with languages like C? Especially on Windows?

  1. If I want to use some other library, what do I need from the library? Header files .h and ..?

  2. What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?

  3. Does it matter how was the library compiled? I mean, is it possible to use, on Windows, a C++ library compiled by VC from within my C code compiled by MinGW?

  4. To use another library, what is preferred way? LoadLibrary() or #include <>?

  5. There are some libraries which only provide the source code or .dll - how to use such libraries? Do I have to recompile them every time I rebuild my project?

  6. How do I create one big .exe? Is this called "static linking"?

  7. How to include some random file into .exe? Say a program icon or start-up song?

  8. How do I split my huge .c into smaller ones? Do I need to create for every part a header file which then I include in the part with WinMain() or main()?

  9. If there is a library which needs another library, is it possible to combine these two into one file? Say, python26.dll needs msvcr90.dll and Microsoft.VC90.CRT.manifest

  10. What happens if I don't free previously allocated memory? Is this going to be cleaned up if the program (process) dies?

Well, so many question... Thanks for every info!

解决方案

1: If I want to use some other library, what do I need from the library? Header files .h and ..?

... and, usually a *.lib file which you pass as an argument to your linker.

2: What is the difference between .dll and .dll.a.? .dll and .lib? .dll and .exe? What is .def?

This might be useful: Static libraries, dynamic libraries, DLLs, entry points, headers … how to get out of this alive?

3: Does it matter how was the library compiled? I mean, is it possible to use, on Windows, a C++ library compiled by VC from within my C code compiled by MinGW?

Yes, it matters. For interop between compilers, the normal way is to use a C-style (not C++-style) API, with well-defined parameter-passing conventions (e.g. __stdcall), or to use 'COM' interfaces.

4: To use another library, what is preferred way? LoadLibrary() or #include <>?

#include is for the compiler (e.g. so that it can compile calls to the library); and LoadLibrary (or, using a *.lib file) is for the run-time linker/loader (so that it can substitute the actual address of those library methods into your code): i.e. you need both.

5: There are some libraries which only provide the source code or .dll - how to use such libraries? Do I have to recompile them every time I rebuild my project?

If it's only source then you can compile that source (once) into a library, and then (when you build your project) link to that library (without recompiling the library).

6: How do I create one big .exe? Is this called "static linking"?

Yes, compile everything and pass it all to the linker.

7: How to include some random file into .exe? Say a program icon or start-up song?

Define that in a Windows-specific 'resource file', which is compiled by the 'resource compiler'.

8: How do I split my huge .c into smaller ones? Do I need to create for every part a header file which then I include in the part with WinMain() or main()?

Yes.

9: If there is a library which needs another library, is it possible to combine these two into one file? Say, python26.dll needs msvcr90.dll and Microsoft.VC90.CRT.manifest

I don't understand your question/example.

10: What happens if I don't free previously allocated memory? Is this going to be cleaned up if the program (process) dies?

Yes.

这篇关于编译语言基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆