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

The Archive Base Latest Questions

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

I seem to be forgetting my C++ … I’m trying to declare some functions

  • 0

I seem to be forgetting my C++ …

I’m trying to declare some functions in C in separate sources, and including the appropriate .h when necessary. It compiles OK; but the problem is during linking, where the linker complains about functions already being defined.

I even tried defining the functions as extern, in a (vain) attempt to just declare the functions and let the implementation come true only on the .c.

This is an abridged description of my code:

common.h

#include <stdio.h> 

module1.h

#include 'common.h' #ifndef MODULE1_H_ #define MODULE1_H_ int init(int option); int open(char* db, char* username, char* password); int get(int handler, int date[2], int time[2], int* data, int& rowsize, int& numrows); int put(int handler, int* data, int& datasize, int& numrows); int close(int handler); int finalize(); #endif /* MODULE1_H_ */ 

module2.h

#include 'common.h' #ifndef MODULE2_H_ #define MODULE2_H_ int get1(int handler, int date, int time, int *data, int& datasize, int& rowsize); int put1(int handler, int* data, int datasize); #endif /*MODULE2_H_*/ 

module1.cpp

#include 'module1.h' int init(int option) { ... } int finalize() { ... } int get(int handler, int date[2], int time[2], int* data, int& rowsize, int& numrows) {     .... } ... 

module2.cpp

#include 'module1.h' #include 'module2.h' int get1(int handler, int date, int time, int* data, int rowsize) {   int daterange[2]={date,date};   int timerange[2]={time,time};   int rsize, numrows, result;   result=get(handler, daterange,timerange, data, rsize, numrows);   rowsize=rsize;    if(numrows!=1) printf('Uh oh...\n');   return result; } ... 

Compilation & linkage:

g++ -o module1.o -c module1.cpp g++ -o module2.o -c module2.cpp g++ -fPIC -shared -o library.so module1.o module2.o 

As I said, it compiles OK. The problem is during linkage, where the linker ‘sees’ that there are two implemented functions from module1.h: one from the inclusion of module1.h in module1.cpp; and the other from the inclusion of module1.h together with module2.h in module2.cpp.

I know the functions are supposed to be declared, but I’m obviously doing a faux-pas. Could someone please point out where it is? Thank you in advance.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T13:48:02+00:00Added an answer on May 11, 2026 at 1:48 pm

    Thank you all for your replies and comments. I figured out the problem (it turned out to be a very stupid thing) and am close to solving it (hopefully).

    It turns out it comes from another include file (cfortran.h) which implements a layer for using C function calls in Fortran (and vice-versa). It’s very useful and I’ve been using it with success up until now, but I was ‘blinded’ by the errors; that include’s documentation states that care should be taken when using it in C++ context (not in C) but this is the first instance where that warning actually produces effects.

    Thank you once more for your help.

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

Sidebar

Ask A Question

Stats

  • Questions 163k
  • Answers 163k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A basic way to do this is as follows: $(document).ready(function()… May 12, 2026 at 12:11 pm
  • Editorial Team
    Editorial Team added an answer assuming the new UIViewController is full-screen, the more usual thing… May 12, 2026 at 12:11 pm
  • Editorial Team
    Editorial Team added an answer Lacking any other solutions, what you can do is create… May 12, 2026 at 12:11 pm

Related Questions

I seem to be forgetting my C++ ... I'm trying to declare some functions
I recently ran into an embarrassing situation with some Flash coding where I had
So i'm toying around with stackless python, writing a very simple webserver to teach
I've built a custom UI for my table that has a darker UI and
We are in the process of a multi-year project where we're building a new

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.