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

  • Home
  • SEARCH
  • 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 5937567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:33:35+00:00 2026-05-22T15:33:35+00:00

I have trouble mixing the C and C++ code , I separately compile the

  • 0

I have trouble mixing the C and C++ code , I separately compile the C and C++ code using gcc and g++. The C code calls C++ functions. I compile them separately which go through well. I link both the objects to produce a “.so” file. when i load this module from lua , module loading fails saying some undefined symbol. I am pasting the C and C++ and the lua error here.

File: wrap.c
----------------------------------------------
#include<stdio.h>

//extern "C"{
extern const char* getMobileFromUid(long long );
extern void addToUidHash(long long, char*);
//}
int callcpp (int ac, char **av)
{
    addToUidHash(1, "98866380587");
    fprintf(stderr,"hash:%s",getMobileFromUid(1));
    return 0;
}

File : uid_hash.cc
--------------------------------------------------------
#include <iostream>
#include <string>
#include <map>

typedef std::map<long long, std::string> uidMapType;
uidMapType uidMap;

extern "C"{ 
const char *getMobileFromUid(long long );
void         addToUidHash(long long, char *);
}


//Add the element  to the uid hash 
void 
addToUidHash(long long uid, char *mobile)
{
    uidMap[uid] = mobile;
    return;
}

//print the uid hash 
void 
printUidHash()
{
    uidMapType::const_iterator end = uidMap.end(); 
    for (uidMapType::const_iterator it = uidMap.begin(); it != end; ++it)
    {
        std::cout << "key = " << it->first;
        std::cout << " value = " << it->second << '\n';
    }
    return;
}


//get the mobile number string from the uid of the user 
const char *
getMobileFromUid(long long uid)
{
        uidMapType::iterator iter = uidMap.find(uid);
        if (iter == uidMap.end()) return NULL; 
        return iter->second.c_str();
}


I compile both of them like below 

ravit@ravit-laptop:~$ g++ -c uid_hash.cc -o uid_hash.o 
ravit@ravit-laptop:~$ gcc -c wrap.c -o wrap.o 
ravit@ravit-laptop:~$ ld -shared wrap.o uid_hash.o -o uid_hash.so 


after this i try to load the module from lua and i get an error "undefined" symbol 

ravit@ravit-laptop:~$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require "uid_hash"
error loading module 'uid_hash' from file './uid_hash.so':
    ./uid_hash.so: undefined symbol: _ZNSsaSEPKc
stack traceback:
    [C]: ?
    [C]: in function 'require'
    stdin:1: in main chunk
    [C]: ?
> 

what is this symbol which remains undefined ?

  • 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-22T15:33:36+00:00Added an answer on May 22, 2026 at 3:33 pm

    I think you need to link with the C++ library. c++filt can help you decode the mangled symbol name:

    main% c++filt _ZNSsaSEPKc
    std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char const*)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using SmartGWT but have run into trouble mixing SmartGWT with other
I have trouble with the following piece of code. When I go through with
I have trouble using SSL pages with JMeter, which I previously posted here .
i have trouble with optimization of the code below which is changing css property
I have trouble here using fopen to open files which have paths longer than
I have trouble using Perl grep() with a string that may contain chars that
I have trouble finding way to correctly refactor this code so that there would
i have trouble with calling one view controller to another view controller using segue
I have trouble saving my date field into database using CakePHP. Table column name
I have trouble compiling a class, which has function pointers as member variables. 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.