Attempt to build the Ada Rosetta Code Arithmetic Evaluation Task fails

Hi;

I’m still struggling to re-learn Ada after an approximately forty years of learning it the first time in college.

I’ve gone through a great deal of the AdaCore Learning Ada web site.

I’ve tried using Alire prior to the new 2.x release and got really frustated and gave up.

I tried using Alire 2.x a couple of times after the release announcement and made a little more progress, but still frustrated.

So I’ve been spot-reading John Barness Ada 2012 (preview of 2022) book and looking at the Ada examples on Rosetta Code.

Almost every time that a Rosetta Code Task uses an external package, I run into problems.

I still don’t understand building with GPR, I just just gnatmake directly.

I use Simon Wright’s release of gcc-13.2.0-aarch64 on my Mac (Apple Silicon) and add -Lpath to gnatmake where the path is my local download of the external package source. [Thank you, Simon!]

In this case, it is the simple_components package.

Attempting this in Alire failed (thee simple_components are in the Alire index); so I fail to properly understand how to use Alire, I guess.

Attempting this with gnatmake using the -L/path also fails.

So I have some fundamental failures to understand how to use Ada in non-trivial examples.

Here is a recent attempt:

/opt/gcc-13.2.0-aarch64/bin/gnatmake -L/opt/ext_ada_lib/simple_components/ ./test_simple_parser.adb
gcc -c -I./ -I- ./test_simple_parser.adb
test_simple_parser.adb:3:06: error: file “parsers.ads” not found
test_simple_parser.adb:4:06: error: file “parsers.ads” not found
test_simple_parser.adb:5:06: error: file “strings_edit.ads” not found
test_simple_parser.adb:6:06: error: file “parsers.ads” not found
gnatmake: “./test_simple_parser.adb” compilation error

I’ve been told (moe than once) that using gnatmake for non-trivial things is hard to get right. I really have tried to understand GPR, but I just don’t get it.

Simple questions:
if an Ada with clause contains a period, that implies a directory?

Do I need multiple -L options on the call gnatmake?

Am I too old and/or too dumb to use Ada for non-trivial coding?

Thanks,
Retired Build Engineer

That particular example uses simple component library. You need to get that and add to the gnatmake link. You can get that from here.

The dot on package that is with-ed is a child package of the previous package.

Hi;

I have already downloaded that.

find /opt/ext_ada_lib/simple_components -print | wc -l
1120

tail end of this is:

/opt/ext_ada_lib/simple_components/gnat-sockets-mqtt-streams.adb
/opt/ext_ada_lib/simple_components/strings_edit-integer_edit.ads
/opt/ext_ada_lib/simple_components/gnat-sockets-connection_state_machine-asn1-generic_enumeration.adb
/opt/ext_ada_lib/simple_components/ieee_754-decimal128.ads
/opt/ext_ada_lib/simple_components/apq_sybase.ads
/opt/ext_ada_lib/simple_components/components-python.gpr
/opt/ext_ada_lib/simple_components/generic_indefinite_fifo.adb
/opt/ext_ada_lib/simple_components/parsers-generic_lexer-cpp_blanks.adb

So, do I need to add additional -L options to the gnatmake command line?

Thanks,
Retired Builld Engineer

Attempted just now:

/opt/gcc-13.2.0-aarch64/bin/gnatmake -L/opt/ext_ada_lib/simple_components -L/opt/ext_ada_lib/simple_components/parser-examples ./test_simple_parser.adb
gcc -c -I./ -I- ./test_simple_parser.adb
test_simple_parser.adb:3:06: error: file “parsers.ads” not found
test_simple_parser.adb:4:06: error: file “parsers.ads” not found
test_simple_parser.adb:5:06: error: file “strings_edit.ads” not found
test_simple_parser.adb:6:06: error: file “parsers.ads” not found
gnatmake: “./test_simple_parser.adb” compilation error

find /opt/ext_ada_lib/simple_components -name parsers.ads
/opt/ext_ada_lib/simple_components/parsers.ads

Thanks

-L is where to look for things to link. Usually you want to use -I with gnatmake for source and object files (if they’re in the same directory). Things get more complicated if you’ve used a baroque directory structure.

As far as I know, simple components uses a flat directory, so by default everything is found in the first directory linked. Have you tried to read the manual here?

if you just want to compile the test parser use, you need to specify where the source code is via the -I switch (that’s the uppercase ‘eye’ letter, not ‘el’). You’ll need to specify both the base simple components directory for parser.ads and the parser-examples/parser-tree/ subdirectory for ther files. Try something like:

/opt/gcc-13.2.0-aarch64/bin/gnatmake -I/opt/ext_ada_lib/simple_components -I/opt/ext_ada_lib/simple_components/parser-examples/parsing-tree/ ./test_simple_parser.adb

if you just want to link to the library for you own program you need to also specify the lib directory with both
-L/opt/ext_ada_lib/simple_components/lib/components/
and
-llibcomponents (that’s with a lowercase ‘el’ not an ‘eye’)

along with the -I search path (eye not el) for the source

/opt/gcc-13.2.0-aarch64/bin/gnatmake -I/opt/ext_ada_lib/simple_components -L/opt/ext_ada_lib/simple_components/lib/components/ -llibcomponents ./my_main.adb

I tested these on my machine and they compiled. So unless your paths are wrong (or I hand typed these and made a mistake in the typing), the above shoulld work.

Also note that if you want to go the library approach make sure you have already built the simple components library, which does mean you’ll have to use GPRBUILD to at least build that.

Thanks to you all. I got it to work. I do not know why my last post did not show up containing details of what I did to get it to work. I also do not know what tripped me up.

Again,
Thanks
Retired Build Engineer

I’ve never had much luck with Simple Components on Mac, I actually set up a VPS running debian to do any ada work that requires that library!

I just tried it again, and here’s what happened:

  1. Downloaded alire, added it to path
  2. alr init --bin test_simple_parser
  3. cd test_simple_parser
  4. alr with simple_components
  5. "warn: No solution found after 5 seconds. Do you want to keep solving for a few more seconds? [Y] Yes [N] No [A] Always (default is Yes) Y "
  6. gnutls and unixodbc are now installed via homebrew
  7. alr toolchain --select
  8. Selected gnat-native (in alr1 I was able to use Simon’s aarch64 version that I installed, but “external” is a missing option).
  9. alr build works
  10. Create a new file, src/parsers-simple.ads and paste contents of package Parsers.Simple
  11. Do the same for src/parsers-simple.adb
  12. Edit src/test_simple_parser.adb and replace it with the contents of procedure Test_Simple_Parser
  13. Ran alr build
  14. Failed with:
ⓘ Building test_simple_parser=0.1.0-dev/test_simple_parser.gpr...                
Link
   [link]         test_simple_parser.adb
0  0x104901f43  __assert_rtn + 64
1  0x104803f43  ld::AtomPlacement::findAtom(unsigned char, unsigned long long, ld::AtomPlacement::AtomLoc const*&, long long&) const + 1411
2  0x104820431  ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 19745
3  0x104830b71  ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_7::operator()(unsigned long, ld::FileInfo const&) const + 657
4  0x7ff80e6ab5cd  _dispatch_client_callout2 + 8
5  0x7ff80e6bbe3e  _dispatch_apply_invoke + 214
6  0x7ff80e6ab59a  _dispatch_client_callout + 8
7  0x7ff80e6ba99d  _dispatch_root_queue_drain + 879
8  0x7ff80e6baf22  _dispatch_worker_thread2 + 152
9  0x7ff80e84fc06  _pthread_wqthread + 262
ld: Assertion failed: (resultIndex < sectData.atoms.size()), function findAtom, file Relocations.cpp, line 1336.
collect2: error: ld returned 1 exit status
gprbuild: link of test_simple_parser.adb failed
gprbuild: failed command was: /users/ianozi/.local/share/alire/toolchains/gnat_native_13.2.2_9be96041/bin/gcc test_simple_parser.o b__test_simple_parser.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/generic_stack.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/generic_unbounded_array.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/generic_unbounded_ptr_array.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/generic_segmented_stack.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_argument.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_argument-segmented_stack.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_operation.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_operation-generic_stack.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_operation-segmented_stack.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_source.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_lexer.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_source-text_io.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/stack_storage.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/strings_edit.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_source-get_ada_blank.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_lexer-ada_blanks.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/strings_edit-integer_edit.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/strings_edit-integers.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-string_source.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/tables.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_token.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_token-generic_token_lexer.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/parsers-generic_token-segmented_lexer.o /Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/tables-names.o /Users/ianozi/projects/test_simple_parser/obj/development/parsers-simple.o libtest_simple_parser.a -L/Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/odbc/ -lodbc -lgnutls -lssl -lcrypto -L/Users/ianozi/projects/test_simple_parser/obj/development/ -L/Users/ianozi/projects/test_simple_parser/obj/development/ -L/Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/ -L/Users/ianozi/.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/odbc/ -L/users/ianozi/.local/share/alire/toolchains/gnat_native_13.2.2_9be96041/lib/gcc/x86_64-apple-darwin21.6.0/13.2.0/adalib/ -shared-libgcc -lgnat-13 -Wl,-rpath,@executable_path/../../..//.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c/odbc -Wl,-rpath,@executable_path/..//obj/development -Wl,-rpath,@executable_path/../../..//.local/share/alire/builds/simple_components_4.68.0_da9b0f3a/a5c143428e25d756de95b25a670e2b55c246efccb91dd8a0aa25bb08acbb714c -Wl,-rpath,@executable_path/../../..//.local/share/alire/toolchains/gnat_native_13.2.2_9be96041/lib/gcc/x86_64-apple-darwin21.6.0/13.2.0/adalib -Wl,-rpath,@executable_path/../../..//.local/share/alire/toolchains/gnat_native_13.2.2_9be96041/lib -o /Users/ianozi/projects/test_simple_parser/bin//test_simple_parser
error: Command ["gprbuild", "-s", "-j0", "-p", "-P", "/Users/ianozi/projects/test_simple_parser/test_simple_parser.gpr"] exited with code 4
error: Compilation failed.

I have to wonder if there’s some weirdness going on with rosetta.

EDIT: This is definitely a mac related quirk. I just uploaded the project on Github for anyone to try via alire. Just git clone https://github.com/AJ-Ianozi/test_simple_parser.git && cd test_simple_parser && alr update && alr build and it works fine.

1 Like

This happens if you’re using Xcode/Command Line Tools v15. You could (try to) update to v15.1 or v15.3, but there are still issues with exception handling.

I produced Xcode 15 fix for installed compilers. The GCC 13.2.0 aarch64 and the 13.2 compiler available via this Mac-related index have the fix applied already.

1 Like