The header file cannot be found during gcc compilation.
Source: Internet
Author: User
The gcc compilation fails to find the header file-Linux general technology-Linux technology and application information. The following is a detailed description. First, create the main. c sayhello. c sayhello. h file.
Main. c code:
# Include
# Include "sayhello. h"
Int main (int argc, char ** args)
{
Sayhello ();
Return 0;
}
Sayhello. c code:
# Include
# Include "sayhello. h"
Int sayhello ()
{
Printf ("Hello \ n ");
}
Sayhello. h code:
Int sayhello ();
Test 1:
Put all three files in the same directory chtest. After compiling according to the queried gcc debugging data, the main file can be correctly generated after a series of operations such as the generation of the Connection Library.
Test 2:
I want to test the path specified during gcc compilation. Now I will leave main. c In the chtest folder and create another ch folder. I will transfer sayhello. c and sayhello. h to ch. Compile and generate libsayhello In the ch folder. a or libsayhello. so, and then return to chtest to compile main. c. Use. a or. so directly generates the main file I want.
[Liyang @ LYLinux ch] $ ls
Libsayhello. a sayhello. c sayhello. h sayhello. o
The error message is displayed as follows:
Error 1:
[Liyang @ LYLinux chtest] $ gcc main. c-L/home/liyang/projs/ch/-lsayhello-o main
Main. c: 2: 22: error: sayhello. h: No such file or directory
Error 2:
[Liyang @ LYLinux chtest] $ gcc main. c-I/home/liyang/projs/ch-o main
/Tmp/ccaTcTtp. o: In function 'main ':
Main. c :(. text + 0x12): undefined reference to 'sayhello'
Collect2: ld returned 1 exit status
Experts:
Is there a problem with my tests (cannot I separate main. c and sayhello. c and sayhello. h ?). If there is no problem with such placement, how can we compile the main file in the specified path?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service