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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:15:01+00:00 2026-05-27T13:15:01+00:00

I just finished up a class in C/C++ in a Linux environment and when

  • 0

I just finished up a class in C/C++ in a Linux environment and when I copied over and ran some simple codes on my Mac (OS-X 10.7 Lion), I ran into some errors. I use gcc/g++ on both platforms. It seems that the prototyping isn’t transferring properly: when I prototype the mysin.cpp file, it spits out the errors below, but when I copy the function definition in its place (i.e. put all code in one file), it works fine.

output:

J-MacBook-Pro jh$ g++ -o main main.cpp -lm
Undefined symbols for architecture x86_64:
  "mysin(double, double)", referenced from:
      _main in cc67Vpm6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

mysin.cpp

#include <math.h>

double mysin(double x, double tol) {

  int N;
  int ii = 1;
  double q;
  double sN = x;
  double cont = x;
  double term = x;

  while (fabs(term) > tol) {
    term = term * (-x * x) / ((2 * ii + 1) * (2 * ii));
    sN = sN + term;
    ii = ii + 1;
  }

  return sN;

}

main.cpp

#include <iostream>
#include <math.h>

double mysin(double x, double tol);

using namespace std;

int main(){

  cout << "sin(1) = " << mysin(1, 1e-6) << endl;

}

It seems like the problems are with some type of name mangling, but I can’t really tell what’s going on. Any ideas? Something incredibly obvious I’m missing?

  • 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-27T13:15:02+00:00Added an answer on May 27, 2026 at 1:15 pm

    you need to compile in two stages or compile all c files in one go like

    g++ -o main.o -c main.cpp
    g++ -o mysin.o -c mysin.cpp
    g++ -o main main.o mysin.o -lm
    

    or

    g++ -o main mysin.cpp main.cpp -lm
    

    Otherwise g++ will look only at the main.cpp and cannot find your mysin function

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

Sidebar

Related Questions

I just finished writing my own collecion class, and i'd really like to make
I just finished a project for my cryptography class and it all seems to
I just finished up my Microprocessors class in college just a few weeks ago,
Just finished incorporating PHP_Beautifier into Vim and the fact that it removes whitespace irks
I just finished a class on InfoPath where the teacher had a grim view
I just finished creating a Point class and was working on a Line class
some friends just finished the implementation of an app and they use Custom Exceptions.
I've just finished reading 'Java for Dummies' and have begun to create a simple
I just finished a semester up of C programming for a class I'm in,
I've just finished off an app for the iPhone which, until today, ran fine

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.