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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:36:46+00:00 2026-05-31T21:36:46+00:00

I have a CPP with extern C functions. If they are all in a

  • 0

I have a CPP with extern “C” functions. If they are all in a single file, everything works great. I want to split up the functions into different files just for organizational purpose.

So lets say I have these two files:

File_One.cpp

#pragma once
#include "stdafx.h"
#include <windows.h>
#include "Functions.h"
#include "Variables.h"
#include <string>
#include "File_Two.cpp"

extern "C"
{
    __declspec(dllexport) void MethodOne()
    { 
        MethodTwo();
    }
}

File_Two.cpp

#pragma once
#include "stdafx.h"
#include <windows.h>
#include "Functions.h"
#include "Variables.h"
#include <string>

extern "C"
{
    __declspec(dllexport) void MethodTwo()
    { 
    }
}

I have tried rearranging my include headers in different order, and even place no include headers in file_one.cpp other than the include for file_two.cpp but I always get the same errors.

1) error LNK1169: one or more multiply defined symbols found

2) error LNK2005: _MethodTwo already defined in File_One.obj

What exactly am I doing wrong?
What should I do to fix it?

Thank you!

  • 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-31T21:36:47+00:00Added an answer on May 31, 2026 at 9:36 pm

    You’re probably running into issues because you’re including the File_two.cpp file in your File_one.cpp file. What is happening is that File_two.cpp and File_one.cpp are getting compiled and linked. But because File_two.cpp is included in File_one.cpp, the linker is seeing two copies of MethodTwo, and can’t decide which to use.

    You should move the declarations to a header:

    File_one.h:

    extern "C"
    {
        __declspec(dllexport) void MethodOne()
    }
    

    And include that instead.

    File_two.h:

    extern "C"
    {
        __declspec(dllexport) void MethodTwo();
    }
    

    Then define the functions with their body in their respective .cpp files. No need for extern "C" in the source files.

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

Sidebar

Related Questions

I have a simple cpp file which uses GIO. I have stripped out everything
I have a cw.h file with a bunch of extern functions in it that
I have a cpp file from which I am generating a shared library (using
I have main.cpp (including main function) and func1.cpp, and I want to link these
Let's assume that I have files a.cpp b.cpp and file c.h. Both of the
Can't understand what is a problem here: I have got main.cpp file where I
I am using autoconf. Right now I have an intermediate .cpp file that is
Say I have a lua file: --functions.lua function testadd(a, b) return a+b end How
All the ndk samples only make use of basic C functions declared as extern
I have a static method in a cpp file (not in class) . I

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.