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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:45:59+00:00 2026-05-11T11:45:59+00:00

Greeting Everyone I’m trying to compile and run a multi-language code in C, C++

  • 0

Greeting Everyone

I’m trying to compile and run a multi-language code in C, C++ and fortran using gcc, g++ & f77 respectively in UNIX. My program consists of two parts, one in C, the other in C++. They interface via a main() writen in C+, while the fortran code can be ignored for this case.

I have been having numerous issues with this, most noticabbly a Segmentation Error thats been occuring as I run the executable. The previous two topics of mine have whittled it down, unfortunatly nothing seems to be solving the problem outright other than completely removing any input/output processes in either half of my program, which just isn’t feasible.

Accessing public class memory from C++ using C Output conflicts between C & C++

I need to locate the reason why I recieve Segmentation Errors when I use input/outputs in both parts of my program. All sources compile, all link successfully and I know that each part (C & C++) works when linked alone with no such Segmentation Errors (with modifications to let them work alone of course). I’ve included all the code that interfaces between the two parts and performs input/output functions.

Any help would be much appriciated.

Makefile

products: SlowDynamic.exe  SlowDynamic.exe: main.o SA.o mersenne.o CFE.o BCs.o EMatrix.o Numbering.o KMatrix.o Solve.o MA_57.o blas.o MA_57_Depend.o Metis.o     f77 -L/usr/sfw/lib -R/usr/sfw/lib -lgcc_s -lstdc++ -o SlowDynamic.exe main.o \         SA.o mersenne.o CFE.o MA_57.o blas.o MA_57_Depend.o Metis.o\         BCs.o EMatrix.o Numbering.o KMatrix.o Solve.o  main.o: main.cpp     g++ -c -o main.o main.cpp  SA.o: SA.cpp     g++ -c -o SA.o SA.cpp  mersenne.o: mersenne.cpp     g++ -c -o mersenne.o mersenne.cpp  CFE.o: CFE.c     gcc -c -o CFE.o CFE.c  MA_57.o: MA_57.f     f77 -c -o MA_57.o MA_57.f  blas.o: blas.f     f77 -c -o blas.o blas.f  MA_57_Depend.o: MA_57_Depend.f     f77 -c -o MA_57_Depend.o MA_57_Depend.f  Metis.o: Metis.f     f77 -c -o Metis.o Metis.f  BCs.o: BCs.c     gcc -c -o BCs.o BCs.c  EMatrix.o: EMatrix.c     gcc -c -o EMatrix.o EMatrix.c  Numbering.o: Numbering.c     gcc -c -o Numbering.o Numbering.c  KMatrix.o: KMatrix.c     gcc -c -o KMatrix.o KMatrix.c  Solve.o : Solve.c     gcc -c -o Solve.o Solve.c  clean:      rm *.o Main.exe *.gpi 

main.ccp

#include <iostream> #include 'SA.h'   using namespace std;   int main()  {         Initial.Initialize();      Parent.SA(Initial.Write);      system ('PAUSE');      return 0; } 

SA.h

#ifndef SA_H #define SA_H  #include <vector>  class SimAnneal {      std::vector< std::vector<float> > DensityDomain;      float Solid_Ele_Num, Void_Ele_Num;     float Solid, Void;      double Energy;     double Time;      void Metropolis (double, int, int);     void Next_State (double, int);     double Schedule (double, int);     double ObjFunction ();     void Distribute ();     void Mutate ();     void Convert ();     void PrintDomain ();     void WriteResults (double, double, double, double, double);    public:     int x_max, y_max;     ...     std::vector<float> DensityArray;      std::vector<float> EnergyArray;     ...     void SA (int);     void Initialize (); };  extern SimAnneal Initial, Parent, Child, Mutation, Best;  #endif   

SA.cpp

include <math.h> #include <iostream> #include <fstream>           #include <time.h>            #include <vector>  #include 'SA.h' #include 'CFE.h' #include 'randomc.h'  using namespace std;  SimAnneal Initial, Parent, Child, Mutation, Best;  ...  void SimAnneal::Initialize ()  {     x_max = ReturnX();     y_max = ReturnY();      EnergyArray.resize(x_max*y_max);     DensityArray.resize(x_max*y_max);      ...      Energy = ObjFunction(); }  ...  void SimAnneal::PrintDomain ()  {     static ofstream OutputFile;      if (!OutputFile.is_open())     {         char FileName [] = 'DensityDomain.txt';          OutputFile.open(FileName);          if (!OutputFile)         {             cerr << 'Failed to open ' << FileName << endl;             exit(EXIT_FAILURE);           }          //cout << '\nGenerating 'DensityDomain.txt'... \n' << endl;     }      for (int y = 0; y < y_max; y++)      {             for (int x = 0; x < x_max; x++)          {                   OutputFile << DensityDomain[y][x] << ' ';          }            OutputFile << endl;     }        OutputFile.close(); }  void SimAnneal::WriteResults (double i, double T, double x, double y, double z)  {     static ofstream OutputFile;      if (!OutputFile.is_open()) //check is file has been opened     {         char FileName [] = 'Results.txt';          OutputFile.open(FileName);          if (!OutputFile)         {             cerr << 'Failed to open ' << FileName << endl;             exit(EXIT_FAILURE);  //abort program         }          //cout << '\nWriting to file in progress... \n' << endl;          OutputFile << 'Iterations' << '\t' << 'Temperatures' << '\t' << 'Sum Strain Energy' << endl;  //<< 'SwapNum1' << '\t' << 'SwapNum2' << '\t' << 'Distance' << endl;          OutputFile << endl;          Initial.Time = (int)time(0);     }      OutputFile << i << '\t' << T << '\t' << z << endl;  //'\t' << y << '\t' << z << endl;       if (i == N_max || T <= T_abs)      {            Parent.Time = (int)time(0);          OutputFile << endl                << 'Settings: ' << endl                << 'Initial Temperature: ' << Initial.Temp << endl                << 'Temperature Iterations: ' << i << endl                << 'Step Iterations: ' << N_step << endl                << endl                << 'Results: ' << endl                << 'Final Temperature: ' << Temp << endl                 << 'Minimum: ' << Energy << endl                << 'Computational Time (s): ' << (Parent.Time-Initial.Time) << endl;          OutputFile.close();     } } 

CFE.h

#ifdef __cplusplus extern 'C' { #endif   int ReturnX (); int ReturnY (); void CFE(float density[], float energy[], int Length);  #ifdef __cplusplus  } #endif  

CFE.c

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include 'BCs.h' #include 'EMatrix.h' #include 'Numbering.h' #include 'KMatrix.h' #include 'fg_types.h' #include 'Solve.h'  int ReturnX () {     FILE *infile;     infile = fopen('test05', 'r');      int elemX,elemY;     fscanf(infile, '%i %i', &elemX, &elemY);      fclose(infile);      return elemX; }  int ReturnY () { Same but returns elemY }  void CFE(float density[], float energy[]) {     // Extensive use of fscanf(), printf() & fprintf()     // and the following:  FILE *outfile;  outfile = fopen('File.txt', 'w'); if(outfile == NULL){      } else{     for(n=0;n<8;n++)     {         for(m=0;m<8;m++)         {             fprintf(outfile,'%f',KE[n][m]);             fprintf(outfile,'\t');         }         fprintf(outfile,'\n');     } }  fclose(outfile);   } 
  • 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. 2026-05-11T11:45:59+00:00Added an answer on May 11, 2026 at 11:45 am

    I’d suggest going through your code with a critical eye, and checking out everything that looks even remotely odd.

    I’d do it for you but C++ isn’t in my rotation at the moment and I’m tripping on false positives. For example, this caught my eye:

    if (!OutputFile.is_open()) {     char FileName [] = 'DensityDomain.txt';      OutputFile.open(FileName);      if (!OutputFile)     {         cerr << 'Failed to open ' << FileName << endl;         exit(EXIT_FAILURE);       }      //cout << '\nGenerating 'DensityDomain.txt'... \n' << endl; } 

    Half way down you’re testing if OutputFile is null, after already calling is_open() and open() on it. It looked to me as if either 1) OutputFile won’t be null or 2) you shouldn’t be calling methods on it before you test it. But I was wrong.

    See what I mean?

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

Sidebar

Ask A Question

Stats

  • Questions 157k
  • Answers 157k
  • 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 BlackBerry UI field managers are notoriously annoying when dealing with… May 12, 2026 at 11:07 am
  • Editorial Team
    Editorial Team added an answer There are two differences. The first is mentioned in the… May 12, 2026 at 11:07 am
  • Editorial Team
    Editorial Team added an answer You could try the datetime module, e.g. import datetime now… May 12, 2026 at 11:07 am

Related Questions

Greeting Everyone I'm trying to compile and run a multi-language code in C, C++
Greetings everyone. I'm in need of some experiance here as how to deal with
Greetings Everyone. I'm currently trying to compile a multiple-language program (C, C++ and FORTRAN)
Greetings Everyone. I'm currently writing a multi-language programe in C, C++ and fortran on
Greetings everyone, going to need some help in clearing this exception. I get the

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.