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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:35:14+00:00 2026-06-04T03:35:14+00:00

I’m trying to compile a library with a test.cpp file, but even though i

  • 0

I’m trying to compile a library with a test.cpp file, but even though

i get all the includes needed, i still get:

test.cpp:(.text+0x24): undefined reference to `initdevice(char*)'
test.cpp:(.text+0x4c): undefined reference to `write2device(char*, int)'
test.cpp:(.text+0x68): undefined reference to `closedevice()'
test.cpp:(.text+0x79): undefined reference to `write2device(char*, int)'
collect2: ld returned 1 exit status

The main function:

#include <fstream>
#include <iostream>
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <limits.h>
#include <set>
#include <map>
#include <stdlib.h>
#include <assert.h>
#include <pthread.h>
#include "writerThread.h"
#include "outputdevice.h"
using namespace std;

int writeToFile();

#define FILE_NAME   "/cs/stud/elishae/Documents/elisha.txt"

int main()
{
int status, id;

char *buf = (char *) malloc(10);
buf = "elishaefla";




//writeToFile();

status = initdevice("testFile.txt");

printf("status = %d\n", status);

id = write2device(buf, 10);

printf("id = %d\n", id);

closedevice();

id = write2device(buf, 10);

//printf("id = %d\n", id);

}

The file that holds the wanted functions:

#include <fstream>
#include <iostream>
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <limits.h>
#include <set>
#include <map>
#include <stdlib.h>
#include <assert.h>
#include <pthread.h>
#include "writerThread.h"
using namespace std;

vector<TaskInfo *> taskQueue;

pthread_t writerThread;

pthread_mutex_t taskQueueMutex, condMutuex;

pthread_cond_t newTasksCond;

bool keepRunning;

int gMaxId;

int initdevice(char *filename)
{

int status;


keepRunning = true;



status = initWriterTrhead(&taskQueue, filename, &newTasksCond, &keepRunning);


status = pthread_mutex_init(&taskQueueMutex, NULL);

status = pthread_cond_init(&newTasksCond, NULL);

status = pthread_create(&writerThread, NULL, writerThreadMain, (void *) 1);

return status;
}


int write2device(char *buffer, int length)
{

/*
 * flow: 1) get mutux for taskMap.
 *       2) iterate over map, find lowest ID open to use - either free entry, or entry with wasItWritten == true.
 *       3) write buffer to map.
 *       4) return.
 */

unsigned int i;
TaskInfo *newTask, *taskTemp;
bool emptyEntryFound = false;

char *bufferCopy = (char *) malloc(length);

memcpy(bufferCopy, buffer, length);

newTask = (TaskInfo *) malloc(2*sizeof(int) + sizeof(bool) + length);
newTask->length = length;
newTask->buffer = bufferCopy;
newTask->wasItWritten = false;


pthread_mutex_lock(&taskQueueMutex);
// insert new task to taskMap TODO: check this code... really not sure it's working
for(i = 0; i < taskQueue.size(); i++)
{
    taskTemp = taskQueue.at(i);

    if(NULL == taskTemp)
    {
        printf("ERROR!!! write2device()\n");
        exit(-1);
    }
    if(taskTemp->wasItWritten == true)
    {
        taskTemp = newTask;
        emptyEntryFound = true;
        break;
    }

}

if(false == emptyEntryFound)
{
    // no empty entries on taskQueue, so we'll insert a new entry
    taskQueue.push_back(newTask);

}

newTask->taskId = i;

pthread_mutex_unlock(&taskQueueMutex);

// signal to writerThread new task was inserted to taskQueue
pthread_cond_signal(&newTasksCond);

printf("vector size = %d\n", taskQueue.size());


return newTask->taskId;
}

the Makefile:

.SUFFIXES:      .o .cpp

.cpp.o :
        g++  -Wall -c -o $@ $<


all:    liboutputdevice.a

# remove the old tapestry library and remake the new one
liboutputdevice.a:  outputdevice.o writerThread.o 
        rm -f $@
        ar rc $@ outputdevice.o writerThread.o

# cleaning all created files    
clean:
        rm -f *.o liboutputdevice.a

After i built the lib. with make, this is what im trying to do next.

the way im trying to compile all together:

g++ -Wall -lpthread liboutputdevice.a test.cpp

why am i getting this error?

  • 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-04T03:35:16+00:00Added an answer on June 4, 2026 at 3:35 am

    Put the library at the end:

    g++ -Wall -pthread test.cpp liboutputdevice.a

    Use -pthread instead of -lpthread (see gcc – significance of -pthread flag when compiling).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

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.