Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:07:29+00:00 2026-06-11T03:07:29+00:00

Possible Duplicate: How do I add a directory to C header include path? I

  • 0

Possible Duplicate:
How do I add a directory to C header include path?

I have run into this problem several times, and I thought it would be good to get an explanation from an experienced C or C++ programmer. In the example below I use a sample library name, but the actual name could be anything.

Say I want to run the following MWE:

#include <stdio.h>
#include <mylib/mylib.h> /* Also try mylib2/mylib/mylib.h */

int main (int argc, char **argv) {
    printf ("Hello, World!\n");
    return 0;
}

Further, assume that I have a Linux distribution that, instead of placing mylib.h in /usr/include/mylib/, chooses the directory /usr/include/mylib2/mylib/. So the straightforward command:

$ gcc test.c

would fail with the error:

fatal error: mylib.h: No such file or directory

But I might try to fix the include statement by writing:

#include <mylib2/mylib.h>

This gets me past the first error. But internally, mylib.h refers to other header files in the “usual” way: #include <mylib/anotherheader.h>. So now, even after I have fixed the original include statement in the MWE as #include <mylib2/mylib/mylib.h> the build breaks because mylib.h is attempting to include #include <mylib/anotherheader.h> instead of #include <mylib2/mylib/anotherheader.h>.

What is the standard way around this problem? There must be a simple compilation flag that I am missing. Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:07:31+00:00Added an answer on June 11, 2026 at 3:07 am

    You set up the include path so that it contains /usr/include/mylib2, usually with a command line option to the compiler like -I/usr/include/mylib2.

    Note that usually an header includes related files from the same package using the

    #include "another.h"
    

    syntax, so that it is first searched in a relative to where it is installed. If your library had done this, there would be no problem with

    #include <mylib2/mylib/mylib.h>
    

    but even if it was the case you don’t want your code to depend on where the libraries you use are installed. That dependence should be kept in the build system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I add a directory to C header include path? I
Possible Duplicate: What do I have to add to a layout to hide the
Possible Duplicate: Java GUI repaint() problem? I write a Java code, but I have
Possible Duplicate: Add 1 hour to datetime datatype I have a timestamp stored in
Possible Duplicate: makefile: how to add a prefix to the basename? I have a
Possible Duplicate: Why do some websites add “Slugs” to the end of URLs? This
Possible Duplicate: Add picture at facebook event with Graph API I have been trying
Possible Duplicate: How to add an integer value into NSMutableArray? I wants to create
Possible Duplicate: How to add .php extension using .htaccess url rewriting? I want to
Possible Duplicate: How to add to an NSDictionary When I do that : NSDictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.