-1

I have an Ada program that calls a C function. I have the C object file. I wrote an small test to see if it works. When I run:

$ gnatmake main.adb -largs cfile.o -lpthread

apparently there's no error but the executable file is not created. I would like to know how to get an executable file for my program. gnatmake generates others files (file .Ali and .o) but not the executable. Why?

2
  • Can you provide a bit more about your setup (OS, version of gnat, how you build cfile.o, etc.)? Also if you can show a screenshot of your directory after running the command that fails, maybe one of the files looks out of place. Commented Apr 19 at 16:15
  • In addition, I would need to see the contents of main.adb and the declaration of the C function to help. Commented Apr 20 at 15:28

1 Answer 1

1

I can't give a good answer yet as to why yours is failing, but I can at least provide an example of one that works for me.

I"m using GCC/GNAT 14.2 to compile in msys2 on Windows 11. I don't know a good example of C using posix threads, but I know that std::thread in c++ uses pthread in my implementation, so I'll use that. First the C++ file:

cfile.cpp

#include <thread>
#include <iostream>

void threadTest(){}

using namespace std;

extern "C" {
void do_something(){
   thread t(threadTest);
   cout << "Started Thread" << endl;
   t.join();
   cout << "Finished Thread" << endl;
}
}

I compiled it using the command:

g++ -c cfile.cpp

which generates cfile.o

Next I make a test Ada file:

main.adb

with Ada.Text_IO; use Ada.Text_IO;
        
procedure Main is
   procedure Do_Something
      with Import, Convention => C, External_Name => "do_something";
begin
   Put_Line("Hello World");
   Do_Something;
end;

Finally I compile it with:

gnatmake main.adb -largs cfile.o -lstdc++ -lpthread

Which compiles without error and generates the file main.exe (on linux distros it might just be "main" without an extension). My test folder has the following files:

cfile.cpp  cfile.o  main.adb  main.ali  main.exe  main.o

Running the main.exe gives:

Hello World
Started Thread
Finished Thread

So my first guess is that it is generating the file, but lack of file extension might be throwing you off. Otherwise, perhaps there is a library you are missing and for whatever reason the compiler is bugging and not giving the output (or stderr is redirected somewhere??).

See if my example works for you and if so, maybe we can work backwords to figure out why yours is not working.

Sign up to request clarification or add additional context in comments.

6 Comments

Does anyone know how to format my ada code as ada code? the standard <!-- language: lang-ada --> is no longer working for me like it used to. I switched back to the old editor mode and it still is not working. Then I tried triple tick Ada method and it still doesn't work.
update, it appears to not like ada for some reason, changing it to vhdl gives it close highlighting
@trashgod I just tried that but it doesn't seem to take it on my end. It still looks unhighlighted here. Take a look and see if you see the same thing? Another odd thing: all my old posts still show up using the old methods, but any new posts I make don't render syntax highlight.
Apparently, CommonMark is now extant, and it does not include Ada.
Well that's sad if they don't support Ada anymore. The kick in the boots is that the new editor actually shows syntax highlighting in the preview and detects that it is Ada, but when you post it, it doesn't render. It teases us.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.