简体   繁体   English

Libquantum代码了解Makefile

[英]Libquantum code Understanding Makefile

I tried to run .c file called grover.c in this C application libquantum 我试图在此C应用程序li​​bquantum中运行名为grover.c的.c文件

www.libquantum.de/files/libquantum-1.1.1.tar.gz www.libquantum.de/files/libquantum-1.1.1.tar.gz

Now I this application already contains a Makefile.in and I can generate the executables called shor and grover using the command 现在,我该应用程序已经包含一个Makefile.in,并且可以使用以下命令生成名为shor和grover的可执行文件

./configure 
make
make demos

But when I try to run grover.c using gcc or clan like this 但是当我尝试使用gcc或clan这样运行grover.c时

clang grover.c clang grover.c

It gives me error of lots of undefined function reference. 它给了我很多未定义函数引用的错误。

In function oracle': grover.c:(.text+0x50): undefined reference to quantum_sigma_x' grover.c:(.text+0x89): undefined reference to quantum_toffoli' grover.c:(.text+0xc8): undefined reference to quantum_toffoli' grover.c:(.text+0xf2): undefined reference to quantum_cnot' grover.c:(.text+0x137): undefined reference to quantum_toffoli' grover.c:(.text+0x16b): undefined reference to quantum_toffoli' grover.c:(.text+0x1b0): undefined reference to quantum_sigma_x' 在函数oracle': grover.c:(.text+0x50): undefined reference to Quantum_sigma_x的oracle': grover.c:(.text+0x50): undefined reference to grover.c :(。text + 0x89):未定义对quantum_toffoli' grover.c:(.text+0xc8): undefined reference to quantum_toffoli'grover.c :(。text + 0xf2):未定义对quantum_cnot' grover.c:(.text+0x137): undefined reference to quantum_toffoli'grover.c :(。text + 0x16b)的未定义引用quantum_toffoli' grover.c:(.text+0x1b0): undefined reference to Quantum_sigma_x的quantum_toffoli' grover.c:(.text+0x1b0): undefined reference to '

I need to know how can I remove this error and if I can run this c code called grover.c in this application. 我需要知道如何删除此错误,以及是否可以在此应用程序中运行名为grover.c的C代码。

Thanks, 谢谢,

It looks like your compiler can not find one or more libraries to link to. 看来您的编译器找不到要链接的一个或多个库。 My hunch is that the makefile has the appropriate commands to invoke the linker. 我的直觉是, makefile具有适当的命令来调用链接器。

If you look at your makefile, you probably will see some commands like -L -l, when the flag -L add a directory to the default search path for libraries and the flag -l is used to name the library to link. 如果查看makefile,则当标志-L将目录添加到库的默认搜索路径并且标志-l用于命名要链接的库时,您可能会看到一些命令,例如-L -l。

for example -L/lib/openGL -lglut32 would cause the library libglut32.so.XYZ which is found in the directory /lib/openGL. 例如, -L/lib/openGL -lglut32会导致在目录/ lib / openGL中找到库libglut32.so.XYZ。 (not this is for a Linux system, but it should be fairly similar for Mac). (这不是针对Linux系统的,但对于Mac应该是相当相似的)。

NBXYZ are the version number of the library. NBXYZ是库的版本号。

Once you work this out, there may be issues with the load finding the libraries, especially if they are in non-standard locations. 解决此问题后,负载查找库可能会出现问题,尤其是在非标准位置时。

------------------------ edit -------------------------- ------------------------编辑------------------------- --

After I posted this, and went to bed I realized that I missed a potential case (and thanks to Paul Griffiths for also noticing my omission.....teach me to do multiple things at once). 在我张贴完这篇论文并上床睡觉后,我意识到我错过了一个潜在的案例(并且感谢Paul Griffiths也注意到了我的遗漏.....教我一次做多件事)。

Any how, just compiling a simple file, say hello.c, as clang hello.c -o hello works because everything is in one file and clang will automatically link to the C run-time library. 无论如何,只要编译一个简单的文件(例如hello.c),因为clang hello.c -o hello都可以工作,因为所有内容都在一个文件中,并且clang会自动链接到C运行时库。

If, in your case the code is spread across multiple files, say grover.c and file1.c you would need to do: 如果您的代码分散在多个文件中,例如grover.c和file1.c,则需要执行以下操作:

clang -c grover.c -o grover.o
clang -c file1.c -o file1.o
clang grover.o file1.o -o grover

(or alteratively clang grover.c file1.c -o grover) (或者另外更改clang grover.c file1.c -o grover)

SO what the first two lines are doing is translating the source-code files (grover.c and file1.c) into object files. 因此,前两行的工作是将源代码文件(grover.c和file1.c)转换为目标文件。 THe third line covers the two object files into an executable. 第三行将两个目标文件覆盖为可执行文件。

Finally, both these cases can be involved. 最后,这两种情况都可以涉及。 You could have multiple files as well as missing libraries. 您可能有多个文件以及缺少的库。

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

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