gem5-users@gem5.org

The gem5 Users mailing list

View all threads

Best practice for linking non-SimObjects with gem5

O
Olumide
Wed, Nov 27, 2024 5:37 PM

Hi gem5-users,

I've got two related questions:

Question 1:
I implemented a set of functions in a simple non-SimObject C++ source
and header (configuration.hh/configuration.cc) that contains some
functionality that I intend to call from my SimObject.

My SConscript file looks like this:

Import("*")

SimObject("Generator.py", sim_objects=["GeneratorSimObject"])

Source("generator.cc")

Library('configuration', ['configuration.cc'])

Is this best practice to add non-SimObjects to gem5?

Question 2:
The above SConscript builds my project successfully, however when I
include configuration.hh in my SimObject source, generator.cc, I get the
error:

expected initializer before 'namespace'
13  | namespace: gem5

On line 13 of generator.cc.

I cannot for the life of me figure out what's going wrong.

BTW, I'm being naughty and using #pragma once. I hope that's not the
problem.

Regards,

  • Olumide
Hi gem5-users, I've got two related questions: Question 1: I implemented a set of functions in a simple non-SimObject C++ source and header (configuration.hh/configuration.cc) that contains some functionality that I intend to call from my SimObject. My SConscript file looks like this: Import("*") SimObject("Generator.py", sim_objects=["GeneratorSimObject"]) Source("generator.cc") Library('configuration', ['configuration.cc']) Is this best practice to add non-SimObjects to gem5? Question 2: The above SConscript builds my project successfully, however when I include configuration.hh in my SimObject source, generator.cc, I get the error: expected initializer before 'namespace' 13 | namespace: gem5 On line 13 of generator.cc. I cannot for the life of me figure out what's going wrong. BTW, I'm being naughty and using #pragma once. I hope that's not the problem. Regards, - Olumide
O
Olumide
Wed, Nov 27, 2024 6:38 PM

Turns out a semi-colon was missing at the end of the configuration.hh.
So that was an easy fix. SConscript can now build my project, however
there is a linker error/undefined reference to the function that I am
trying to call from configuration.hh.

Hopefully this will be fixed by the following addition to my SConscript:

configuration_src = ['configuration.cc']

configuration_lib = env.Library('configuration', configuration_src)

env.Append(LIBS=[configuration_lib])

Not sure if this the best way to go about it tho.

Regards,

  • Olumide

On 27/11/2024 17:37, Olumide wrote:

Hi gem5-users,

I've got two related questions:

Question 1:
I implemented a set of functions in a simple non-SimObject C++ source
and header (configuration.hh/configuration.cc) that contains some
functionality that I intend to call from my SimObject.

My SConscript file looks like this:

Import("*")

SimObject("Generator.py", sim_objects=["GeneratorSimObject"])

Source("generator.cc")

Library('configuration', ['configuration.cc'])

Is this best practice to add non-SimObjects to gem5?

Question 2:
The above SConscript builds my project successfully, however when I
include configuration.hh in my SimObject source, generator.cc, I get the
error:

expected initializer before 'namespace'
13  | namespace: gem5

On line 13 of generator.cc.

I cannot for the life of me figure out what's going wrong.

BTW, I'm being naughty and using #pragma once. I hope that's not the
problem.

Regards,

  • Olumide
Turns out a semi-colon was missing at the end of the configuration.hh. So that was an easy fix. SConscript can now build my project, however there is a linker error/undefined reference to the function that I am trying to call from configuration.hh. Hopefully this will be fixed by the following addition to my SConscript: configuration_src = ['configuration.cc'] configuration_lib = env.Library('configuration', configuration_src) env.Append(LIBS=[configuration_lib]) Not sure if this the best way to go about it tho. Regards, - Olumide On 27/11/2024 17:37, Olumide wrote: > Hi gem5-users, > > I've got two related questions: > > Question 1: > I implemented a set of functions in a simple non-SimObject C++ source > and header (configuration.hh/configuration.cc) that contains some > functionality that I intend to call from my SimObject. > > My SConscript file looks like this: > > > Import("*") > > SimObject("Generator.py", sim_objects=["GeneratorSimObject"]) > > Source("generator.cc") > > Library('configuration', ['configuration.cc']) > > > Is this best practice to add non-SimObjects to gem5? > > > Question 2: > The above SConscript builds my project successfully, however when I > include configuration.hh in my SimObject source, generator.cc, I get the > error: > > expected initializer before 'namespace' > 13  | namespace: gem5 > > On line 13 of generator.cc. > > I cannot for the life of me figure out what's going wrong. > > BTW, I'm being naughty and using #pragma once. I hope that's not the > problem. > > > Regards, > > - Olumide