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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:27:15+00:00 2026-06-03T01:27:15+00:00

When compiling a C++ program on linux using g++, how do you link in

  • 0

When compiling a C++ program on linux using g++, how do you link in your own header files?

For example I have a file with the following includes:

#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#include "3DCurve.h"

When I compile using the following command:

 g++ -lm -lglut -lGL -o 3dcurve Example_8_1.cpp

I get the following error:

undefined reference to 'draw3Dcurve(double, double, double, double, double, double)'

How do I link the the 3DCurve.h file into the compiler? The header file and its implementation sit in the same folder as the file I’m compiling. My understanding is that the compiler should just find it, if it is sitting in the same folder.

What am I not getting?

  • 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-03T01:27:16+00:00Added an answer on June 3, 2026 at 1:27 am

    One doesn’t link to header files, one just includes them. But if the header file has a corresponding implementation file, you either have to include that in the compilation line, or make an object file out of that, and include that in the compilation line. From your error, it looks like you have an implementation file that hasn’t been dealt with appropriately.

    Assuming the implementation if DCurve.h is called 3DCurve.cpp then you could do this:

    g++ -lm -lglut -lGL -o 3dcurve 3DCurve.cpp Example_8_1.cpp
    

    Other options are to make an object file 3DCurve.o using the -c g++ option, and then

    g++ -lm -lglut -lGL -o 3dcurve 3DCurve.o Example_8_1.cpp
    

    Or, make a shared or static library and use it like you would another 3rd party library.

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

Sidebar

Related Questions

I have used the following code to create two threads: //header files #include <pthread.h>
I'm having problems compiling the following program. I'm using gcc -framework Foundation inherit8.1m and
I am compiling a message passing program using openmpi with mpicxx on a Linux
I have a program which statically links to another library in linux using -L(mylib.a)
I'm using C++ under Linux compiling with standard GCC. In my program I want
I am compiling my program that will run on linux gcc 4.4.1 C99. I
I was compiling a C++ program in Cygwin using g++ and I had a
I am getting the following error while compiling a sample program in Qt 4.5
I have a very large program which I have been compiling under visual studio
Will the following program cause any problem during compiling and execution process? class A{

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.