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

Related Questions

There seem to many ways to skin this particular cat - but which is
Seem to be having an issue with std::auto_ptr and assignment, such that the object
I seem to be missing something about LINQ. To me, it looks like it's
There seem to be many ways to define singletons in Python. Is there a
I seem to remember reading something about how it is bad for structs to
I seem right now to be embroiled in a debate with another programmer on
I seem to make this mistake every time I set up a new development
I seem to always have problems with converting data to and from XML in
There seem to be two rival Eclipse plugins for integrating with Maven: m2Eclipse and
I seem to be getting a strange error when I run my tests in

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.