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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:24:29+00:00 2026-06-01T20:24:29+00:00

I am writing a graphics program in C/C++ using OpenGL. I have a bunch

  • 0

I am writing a graphics program in C/C++ using OpenGL. I have a bunch of .c files and right now, I am trying to call a function from main.cpp in assignment1gui.c. The teacher has given me a file with the compile code. It looks like this:

OBJS   = assignment1gui.o shadertools.o main.o
TARGET = ass1

CXX = gcc

DBFLAGS  = -O0 -g3 -ggdb3 -fno-inline

WFLAGS   = -Wall -ansi
GLFLAGS  = `pkg-config --cflags gtk+-2.0`
LGLFLAGS = `pkg-config --libs gtk+-2.0` -lGL -lGLEW -lGLU -lglut

CXXFLAGS = $(WFLAGS) $(DFLAGS) $(GLFLAGS)
LDFLAGS  =  -export-dynamic -lXext -lX11 $(LGLFLAGS)


all: $(TARGET)
clean:
    rm -f $(OBJS) $(TARGET)

.SUFFIXES: .cc
.cc.o:
    $(CXX) -c $(CXXFLAGS) $<
.c.o:
    $(CXX) -c $(CXXFLAGS) $<
$(TARGET): $(OBJS)
    $(CXX) -o $(TARGET) $(OBJS) $(LDFLAGS) 

The function I am trying to call is “drawPloygonLine()”. I have declared this in “assignment1gui.h”, and the definition, as I mentioned earlier, is in main.cpp.

From all the help on the Internet, I realized that there must some problem with the compile code. But I am not sure. Could someone please help me out?

Sorry I left out this part earlier. The errors I am getting are:

assignment1gui.o: In function `on_btn_color_color_set':
assignment1gui.c:(.text+0x1c): undefined reference to `drawPolygonLine'
assignment1gui.o: In function `on_rb_tool_line_toggled':
assignment1gui.c:(.text+0x8b): undefined reference to `drawPolygonLine'
assignment1gui.o: In function `on_rb_tool_circle_toggled':
assignment1gui.c:(.text+0xfc): undefined reference to `drawPolygonLine'
assignment1gui.o: In function `on_rb_tool_rect_toggled':
assignment1gui.c:(.text+0x16d): undefined reference to `drawPolygonLine'
assignment1gui.o: In function `on_rb_tool_edit_toggled':
assignment1gui.c:(.text+0x24a): undefined reference to `drawPolygonLine'
collect2: ld returned 1 exit status
make: *** [ass1] Error 1

The C/C++ files I have in the folder are main.cpp, assignment1gui.c and shadertools.c. I also have two header files- assignment1gui.h and shadertools.h. As I have mentioned earlier, I used the assignment1gui.h file to declare the new function “drawPolygonLine();”

Addition:
The declaration of the “drawPolygonLine();” is now in “main.h” and it looks like this:

#ifndef MAIN_H
#define MAIN_H

extern void drawPolygonLine();

#endif  /* MAIN_H */

Both main.cpp and assignment1gui.c have “#include “main.h”” at their beginning. The definition of drawPolygonLine() is:

void drawPolygonLine()
{
    if(option[opCount-1]==4 && drawn==false)
    {           
        vCount++;
        vertex[vCount].x=A;
        vertex[vCount].y=B;
        lines=lines+2;
        vCount++;
        vertex[vCount].x=polyX;
        vertex[vCount].y=polyY;   
        clicks=0;     
        drawn=true;
    }

}

All the variables used in the function are global in main.cpp.

An example of how I am calling drawPolygonLine(); in assignment1gui.c is in this function:

void on_btn_color_color_set(GtkColorButton *colorbutton, gpointer user_data)
{
    drawPolygonLine();

    GdkColor color;
    gtk_color_button_get_color(colorbutton, &color);
    printf("Color set rgb=(%i,%i,%i)\n",color.red,color.green,color.blue);
}

I hope this makes it clear.

  • 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-01T20:24:30+00:00Added an answer on June 1, 2026 at 8:24 pm

    The problem is that main.cpp isn’t understood by this make file, since it only has rules for .cc or .c files. I suspect that main.o isn’t being built – or, more likely, since you’re getting as far as a failed compile, there is another file called main.c or main.cc which IS included in your program, but doesn’t have drawPolygonLine() defined in it.

    To solve this:

    1. Remove or rename any existing main.c or main.cc files.

    2. If your program is actually a C program, then change the filename to main.c

    3. If your program is a C++ program, you could try changing the extension to .cc, but I suspect you’ll then run in to problems since you’re using gcc rather than g++. In this case, I’d also change:

      CXX = gcc
      

      to

      CXX = g++
      

    Remember that although a lot of C code is also valid C++ code, there are many subtle differences – and the best practices are very different in each language. For this reason, it’s best to treat C and C++ as different languages.


    If this doesn’t fix it:

    • Check that the function signature of drawPolygonLine() declared in your header file is the same as the way it’s defined in your main file. Check that these declarations match with the way you’ve called it.
    • Check that the files that call drawPolygonLine() have #include "assignment1gui.h" at the top
    • Check that drawPolygonLine() isn’t declared as static (static functions aren’t visible outside their translation unit – so the linker won’t see them when compiling two output files together)

    Also, it’s good practice to have the function declaration in the header file corresponding to the source file it’s defined in – so if you want to call a function in main.c from assignment.c, you would usually put the declaration in main.h, and #include it at the top of assignment.c. This won’t be the cause of the problem that you’re having, but it’s good practice to get used to.

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

Sidebar

Related Questions

I'm writing a little app that displays some graphics and just now I'm trying
I'm writting a small graphics program using directx9 which imports some model files created
I'm writing a program that uses the Qt Graphics View framework. I have subclassed
I'm writing a simple graphics engine that draws textures on the screen using OpenGL
I am writing a program in C, using OpenGL, to draw some primitives (lines,
I'm writing a plug-in for a program where I have a custom user control
In writing an ActionScript 3 program, I am trying to make it so that
I'm learning Android by writing a game and have a problem with the graphics
I'm writing opengl code in python using the library pyglet. When I draw to
I am writing an iphone (IOS 4) program that capture live video from the

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.