简体   繁体   中英

Libquantum code Understanding Makefile

I tried to run .c file called grover.c in this C application libquantum

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

./configure 
make
make demos

But when I try to run grover.c using gcc or clan like this

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'

I need to know how can I remove this error and if I can run this c code called grover.c in this application.

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.

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.

for example -L/lib/openGL -lglut32 would cause the library libglut32.so.XYZ which is found in the directory /lib/openGL. (not this is for a Linux system, but it should be fairly similar for Mac).

NBXYZ are the version number of the library.

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).

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.

If, in your case the code is spread across multiple files, say grover.c and file1.c you would need to do:

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)

SO what the first two lines are doing is translating the source-code files (grover.c and file1.c) into object files. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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