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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:03:24+00:00 2026-06-16T02:03:24+00:00

I have a compilation basic error. My main on a nutshell is: main.cpp #include

  • 0

I have a compilation basic error.

My main on a nutshell is:

main.cpp

#include "sendArrayObj.h"
sendArrayObj* sendqueue;

void foo(){
    int i = sendqueue->count()
}

int main(){
    int i =10;
    sendqueue = new sendArrayObj(i);
    foo();
}

sendArrayObj.h

using namespace std;
#include <string.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>


class sendArrayObj{
private:
    int size,toEnqueue,toDequeue,lastDequeuedInd;
    unsigned long long totalEnqueued,totalDequeued;

public:
    char** arr;
    int* lengths;
    sendArrayObj(int size);
    void enqueue(string str);
    char* dequeue();
    int count();
    int getDequeuedSize();

};

sendArrayObj.cpp

#include "sendArrayObj.h"

pthread_mutex_t mutex_requestsqueue = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex_count = PTHREAD_MUTEX_INITIALIZER;


sendArrayObj::sendArrayObj( int size){
this->size = size;
toEnqueue = 0;
toDequeue = 0;
totalEnqueued = 0;
totalDequeued = 0;
lastDequeuedInd = -1;
arr = (char**)malloc(size*sizeof(char*));//alloc number of pointers
lengths = (int*)malloc(size*sizeof(int));//alloc number of lengths
}

void sendArrayObj::enqueue(std::string str){
int strSize = str.size();
pthread_mutex_lock( &mutex_requestsqueue );
if (arr[toEnqueue]!= NULL){
    free(arr[toEnqueue]);
    toDequeue = (toDequeue+1)%size;
    totalDequeued++;
}
arr[toEnqueue] = (char*)malloc(strSize);
memcpy(arr[toEnqueue],(char*)str.c_str(),strSize);
lengths[toEnqueue] = strSize;
toEnqueue = (toEnqueue+1)%size;
totalEnqueued++;
pthread_mutex_unlock( &mutex_requestsqueue );
}



char* sendArrayObj::dequeue(){
pthread_mutex_lock( &mutex_requestsqueue );
//allocate memory to the ans 
//char* ans = new char[lengths[toDequeue]];
char* ans = arr[toDequeue];
lastDequeuedInd = lengths[toDequeue];
//memcpy(ans,arr[toDequeue],lengths[toDequeue]);
//if (arr[toDequeue]!=NULL){
    //delete[] arr[toDequeue];
arr[toDequeue] = NULL;
//}
toDequeue = (toDequeue+1)%size;
totalDequeued++;
//printf("totalDequeued is %d\n",totalDequeued);
pthread_mutex_unlock( &mutex_requestsqueue );
return ans;

}



int sendArrayObj::count(){
pthread_mutex_lock( &mutex_count );
int ans = totalEnqueued-totalDequeued; 
pthread_mutex_unlock( &mutex_count );
//printf("count is %d\n",ans);
return ans;
}

int sendArrayObj::getDequeuedSize(){    
return lastDequeuedInd;
}

my compilation batch is

g++ -g -pthread utils/hregex.cpp ExcludeFields.cpp utils/sha1.cpp utils/utils.cpp utils/base64.cpp utils/xmlhelper.cpp utils/messagehelper.cpp utils/safe_queue.cpp utils/parser.cpp utils/default_config.cpp ExcludesParameters.cpp main_process_helper.cpp main.cpp -Iutils -Ibusiness_objects -o telepath_sniff

and the files are in the folder “utils”

Any idea of why I’m getting it??

Thanks

  • 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-16T02:03:25+00:00Added an answer on June 16, 2026 at 2:03 am

    You must tell the linker which object files to link into your application.

    edit:

    You posted the following command, with readability tweaks by me:

    g++ -g -pthread 
    utils/hregex.cpp \
    ExcludeFields.cpp \
    utils/sha1.cpp \
    utils/utils.cpp \
    utils/base64.cpp \
    utils/xmlhelper.cpp \
    utils/messagehelper.cpp \
    utils/safe_queue.cpp \
    utils/parser.cpp \
    utils/default_config.cpp \
    ExcludesParameters.cpp \
    main_process_helper.cpp \
    main.cpp -Iutils -Ibusiness_objects -o telepath_sniff
    

    With GNU tools, you put dependencies after what depends on it.

    E.g., if main.cpp depends on foobar.cpp, you write

    g++ main.cpp foobar.cpp
    

    because the linker will try to link main.cpp, and then keep a list of references that need to be solved later. You ordered it wrongly.

    And finally, you are missing sendArrayObj.cpp alltogether.

    So,

    • put what depends first, and that what it depends upon behind it
    • add sendArrayObj.cpp to your build script command

    Sidenote: You should generally

    • use include guards
    • avoid global variables
    • avoid manual memory management
    • not expose writable member variables
    • either define copy semantics well or forbid copying alltogether
    • not use C headers (e.g. use cstdio, not stdio.h)
    • make member functions const if they are not supposed to change the observable state of an instance of your class
    • not put using namespace in header files
    • prefer standard library containers like std::list or std::vector over dynamically allocated arrays
    • write destructors for classes that manage memory
    • release memory
    • use a consistent indendation scheme
    • not include headers you don’t need, this costs you time and therefore money
    • use a build system (e.g. makefiles, IDE project files, cmake, Scons)
    • get good introductory literature on topics you are a newbie in
    • not write projects that big if you have not read good introductory literature, which is doubly triply true of C++
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get some basic dynamic code compilation working using the
I have two basic Cpp tasks, but still I have problems with them. First
I am new to Drools Guvnor and have set up a basic rool framework
I am new to JS and need some basic help: I have a spreadsheet
I am new to C++, so forgive me for basic question. I have project
#include<iostream> #include<vector> std::vector<std::string> vector1; int main() { vector1.push_back(adadad); std::vector<std::string> vector2; vector2.push_back(adadd); if (vector1==vector2) {
We have 2 different compilation machine: red hat as4 and as5. Our architects require
G'day there! I have a problem compilation of mupdf for android Compile thumb :
I apologize for bothering you all, but I have a little compilation problem with
I have a client website where I recently started getting compilation errors: CS0029: Cannot

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.