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 3936284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:55:43+00:00 2026-05-19T23:55:43+00:00

I have a class file (header and cpp) that I made, that I want

  • 0

I have a class file (header and cpp) that I made, that I want to use in my main.cpp file. I generated a qmake project file (from the current directory of my main.cpp) and added the header and cpp with:

HEADERS += $$quote(/home/myusername/projects/src/myclass.h)
SOURCES += $$quote(/home/myusername/projects/src/myclass.cpp)
SOURCES += main.cpp

when I run the makefile, it seems to work until it gets to the part of my main.cpp where i include the header file and then it says: fatal error, no such file or directory

I feel like i’m making a really basic mistake, but I can’t seem to figure it out.

  • 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-05-19T23:55:44+00:00Added an answer on May 19, 2026 at 11:55 pm

    First, using absolute paths in a project file is definitely a bad idea.

    If that class is a part of the project, but is located in another directory, use relative paths both in the project file and in the #include directive, using #include "relative/path/myclass.h" syntax.

    If that class is not a part of the project, then you should compile it as a library, then use qmake with the following options:

    qmake INCLUDEPATH+=/path/to/the/header LIBS+=-L/path/to/the/library
    

    And add the library name to the project file:

    LIBS += -llibraryname
    

    Then you may include your class as #include <myclass.h>, note the <> syntax.

    Note that workstation-specific things go to the command line, but the workstation-independent library name goes to the project file. If you want to provide some sensible default location, you could use the following trick:

    unix { # default path for the Unix systems
      isEmpty(MYLIB_PATH): MYLIB_PATH = /usr/local
    }
    INCLUDEPATH += $$MYLIB_PATH/include
    LIBS += -L$$MYLIB_PATH/lib
    

    Then, if you want, you can still override the path from the command line:

    qmake MYLIB_PATH=/home/myusername/mylib
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class header file called Grid.h that contains the following 2 private
I have an header file, sieve.h, that has no cpp file. Here is what
I currently have a project with 3 files. One DBheader.h header file that includes:
I have all the class definitions in a header file: ModelModule.h. I have provided
i make one class file for jar. and this class have use wurfl. and
I have a class in the file AType.h and it is implemented in AType.cpp.
I currently have a program where my main code is in a file main.cpp.
Basically I have code which looks like this inside a header file: class Bar;
I have one class, called A, and it has it's own header file. Then
Is it possible to make a C++ header file (.h) that declares a class,

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.