简体   繁体   English

在Linux中将库与AC程序链接的问题

[英]Problems with linking a library with a c program in linux

I want to run serial commands from a Bealgebone to a 4Dsystems display. 我想从Bealgebone到4Dsystems显示器运行串行命令。 Therefore I copied the c library found here into a directory and created a test program main.c: 因此,我将此处找到的c库复制到目录中,并创建了一个测试程序main.c:

#include "Picaso_const4D.h" 
#include "Picaso_Serial_4DLibrary.h"

int main(int argc,char *argv[])
{
    OpenComm("/dev/ttyUSB0", B115200);  // Matches with the display "Comms" rate
    gfx_BGcolour(0xFFFF);
    gfx_Cls();
    gfx_CircleFilled(120,160,80,BLUE);
    while (1) {}
}

Now when I do gcc -o main main.c its says 现在当我做gcc -o main main.c它说

main.c:2:37: fatal error: Picaso_Serial_4DLibrary.h: No such file or directory main.c:2:37:致命错误:Picaso_Serial_4DLibrary.h:没有此类文件或目录

So I try linking it: 所以我尝试链接它:

gcc main.c  -L. -lPICASO_SERIAL_4DLIBRARY

which gives me the same error. 这给了我同样的错误。 Then I tried to create a static library: 然后我尝试创建一个静态库:

gcc -Wall -g -c -o PICASO_SERIAL_4DLIBRARY PICASO_SERIAL_4DLIBRARY.C

which gives me this: 这给了我这个:

PICASO_SERIAL_4DLIBRARY.C:1:21: fatal error: windows.h: No such file or directory compilation terminated. PICASO_SERIAL_4DLIBRARY.C:1:21:致命错误:windows.h:没有此类文件或目录编译终止。

What am I doing wrong? 我究竟做错了什么? the git page clearly says this library is created for people who do not run windows. git页面明确表示此库是为不运行Windows的用户创建的。

Thanks in advance! 提前致谢!

You're not getting a linker error; 您没有收到链接器错误; you're getting a preprocessor error. 您收到预处理器错误。 Specifically, your preprocessor can't find Picaso_Serial_4DLibrary.h. 具体来说,您的预处理器找不到Picaso_Serial_4DLibrary.h。 Make sure that it's in your include path; 确保它在您的包含路径中; you can add directories to your include path using the -I argument to gcc. 您可以使用gcc的-I参数将目录添加到包含路径。

You've had two problems. 您遇到了两个问题。 First was the picaso_whatever.h file that couldn't be found. 首先是找不到的picaso_whatever.h文件。 You fixed that with the -I you added. 您使用添加的-I修复了该问题。 But, now, the picaso.h wants windows.h 但是,现在,picaso.h需要windows.h

What are you building on? 你在建什么? WinX or BSD/Linux? WinX还是BSD / Linux?

If you're compiling on WinX, you need to install the "platform sdk" for visual studio. 如果您在WinX上进行编译,则需要为Visual Studio安装“ platform sdk”。

If you're using mingw or cygwin, you need to do something else. 如果您使用的是mingw或cygwin,则需要执行其他操作。

If on WinX, cd to the C: directory. 如果在WinX上,则cd到C:目录。 Do find . -type f -name windows.h 一定要find . -type f -name windows.h find . -type f -name windows.h and add a -I for the containing directory. find . -type f -name windows.h并为包含的目录添加-I。

If under Linux, repeat the find at the source tree top level. 如果在Linux下,请在源树顶层重复查找。 Otherwise, there is probably some compatibility cross-build library that you need to install. 否则,可能需要安装一些兼容的跨版本库。

Or, you'll have to find WinX that has it as Picaso clearly includes it. 或者,您必须找到具有它的WinX,因为Picaso明确包含了它。 You could try commenting out one or more of the #include's for it and see if things are better or worse. 您可以尝试为此注释掉一个或多个#include,以查看情况是好是坏。

If you can't find a real one, create an empty windows.h and add -I to it and see how bad [or good] things are. 如果找不到真正的Windows,则创建一个空的windows.h并在其中添加-I,以查看问题的严重程度。

You may need the mingw cross-compiler. 您可能需要使用mingw交叉编译器。 See https://forums.wxwidgets.org/viewtopic.php?t=7729 参见https://forums.wxwidgets.org/viewtopic.php?t=7729

UPDATE: 更新:

Okay ... Wow ... You are on the right track and close, but this is, IMO, ugly WinX stuff. 好的...哇...您走在正确的轨道上,但是,这是IMO,丑陋的WinX东西。

The primary need of Picaso is getting a serial comm port connection, so the need from within windows.h is [thankfully] minimal. Picaso的主要需求是获得串行通信端口连接,因此[感激]最小化了windows.h内部的需求。 It needs basic boilerplate definitions for WORD, DWORD, etc. 它需要WORD,DWORD等的基本样板定义。

mingw or cygwin will provide their own copies of windows.h. mingw或cygwin将提供他们自己的windows.h副本。 These are "clean room" reimplementations, so no copyright issues. 这些是“无尘室”的重新实现,因此没有版权问题。

mingw is a collection of compile/build tools that let you use gcc/ld/make build utilities. mingw是编译/构建工具的集合,可让您使用gcc / ld / make构建实用程序。

cygwin is more like: I'd like a complete shell-like environment similar to BSD/Linux. cygwin更像是:我想要一个类似于BSD / Linux的完整的类似于shell的环境。 You get bash, ls, gcc, tar, and just about any GNU utility you want. 您会得到bash,ls,gcc,tar和几乎任何所需的GNU实用程序。

Caveat: I use cygwin, but have never used mingw. 警告:我使用cygwin,但从未使用过mingw。 The mingw version of windows.h [and a suite of .h files that it includes underneath], being open source, can be reused by other projects (eg cygwin, wine). Windows.h的mingw版本[及其下面包含的.h文件套件]是开源的,可以由其他项目(例如cygwin,wine)重用。

Under Linux, wine (windows emulator) is a program/suite that attempts to allow you to run WinX binaries under Linux (eg wine mywinpgm). 在Linux下,wine(Windows模拟器)是一个程序/套件,试图允许您在Linux下运行WinX二进制文件(例如wine mywinpgm)。

I git cloned the Picaso library and after some fiddling, I was able to get it to compile after pointing it to wine's version of windows.h 我git克隆了Picaso库,经过一番摆弄,将其指向wine的Windows.h版本后,我得以将其编译。

Picaso's OpenComm is doing CreateFile [a win32 API call]. Picaso的OpenComm正在执行CreateFile [win32 API调用]。 So, you'll probably need cygwin. 因此,您可能需要cygwin。 You're opening /dev/ttyUSB0. 您正在打开/ dev / ttyUSB0。 /dev/* implies cygwin. / dev / *表示cygwin。 But, /dev/ttyUSB0 is a Linux-like name. 但是,/ dev / ttyUSB0是类似于Linux的名称。 You may need some WinX-style name like "COM:" or whatever. 您可能需要一些WinX样式的名称,例如“ COM:”或其他名称。 Under the cygwin terminal [which gives you a bash prompt], do ls /dev and see what's available. 在cygwin终端[会向您显示bash提示]下,执行ls / dev并查看可用的工具。

You can get cygwin from: http://cygwin.com/ If you have a 64 bit system, be sure to use the 64 bit version of the installer: setup-x86_64.exe It's semi-graphical and will want two directories, one for the "root" FS and one to store packages. 您可以从以下网站获得cygwin: http : //cygwin.com/如果您使用的是64位系统,请确保使用64位版本的安装程序:setup-x86_64.exe这是半图形的,需要两个目录,一个用于“根” FS,并用于存储软件包。 On my system, I use C:\\cygwin64 and C:\\cygwin64_packages--YMMV. 在我的系统上,我使用C:\\ cygwin64和C:\\ cygwin64_packages--YMMV。

Note that the installer won't install gcc by default. 请注意,默认情况下,安装程序不会安装gcc。 You can [graphically] select which packages to install. 您可以[以图形方式]选择要安装的软件包。 You may also need some "devel" packages. 您可能还需要一些“开发”软件包。 They have libraries and .h files that a non-developer wouldn't need. 它们具有非开发人员不需要的库和.h文件。 As, docs mention, you can rerun the installer as often as you need. 正如文档所述,您可以根据需要多次重新运行安装程序。 You can add packages that you forgot to specify or even remove ones that you installed that you don't need anymore. 您可以添加忘记指定的软件包,甚至删除不再需要的已安装软件包。

Remember that you'll need to adjust makefile -I and/or -L option appropriately. 请记住,您需要适当地调整makefile -I和/或-L选项。 Also, when building the picaso library, gcc generated a ton of warnings about overflow of a "large integer". 同样,在构建picaso库时,gcc会生成大量有关“大整数”溢出的警告。 The code was doing: 该代码正在执行:

#define control_code -279
unsigned char buf[2];
buf[0] = control_code >> 8;
buf[1] = control_code;

The code is okay, and the warning is correct [because the code is sloppy]. 代码还可以,并且警告是正确的(因为代码草率)。 If the code had done: 如果代码已完成:

#define control_code -279
unsigned char buf[2];
buf[0] = (unsigned) control_code >> 8;
buf[1] = (unsigned) control_code;

it probably would have been silent. 它可能会保持沉默。 Use -Wno-overflow in your Makefile to get rid of the warnings rather that edit 50 or so lines 在Makefile中使用-Wno-overflow摆脱警告,而编辑50条左右的行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM