[aspectc-user] AscpectC++ with Qt using Qt Creator 4.0.2

os at aspectc.org os at aspectc.org
Thu Feb 8 18:40:53 CET 2018


Dear Alberto,

Am 02.02.2018 um 19:50 schrieb E. Alberto Morales:
> I want to use AspectC++ with Qt but i have a problem to compile the
> source codes.
> 
> Let me explain:
> 
> * I downloaded the examples that were on the aspectc++ page and
> following this tutorial: https://www.aspectc.org/doc/ac4qt.pdf.
> * I downloaded aspectc++ 2.0 binaries and copy to /bin directory. Then i
> set QMAKEFEATURES with the path of acxx.prf (in this step i also have a
> problem but i solved with this instruction:
> https://forum.qt.io/topic/81179/qmake-does-not-read-prf-file-located-in-project-root-directory/2).
> * This is the helloworld.pro <http://helloworld.pro>
> (https://i.imgur.com/sMXFC4u.png) and as you see acxx.prf is read.
> * But when i want to build the project this error message appear
> (https://i.imgur.com/eoWDCuQ.png) and this is compilation error
> (https://i.imgur.com/u9c9g1M.png).
> * This is the aspect code: (https://i.imgur.com/CzYIYcc.png).
> 
> What could be the problem?
> Can we help me to build the example project?

Using ac++ in QtCreator is a bit tricky, but I eventually managed to
compile a simple HelloWorld project.

The problem is that QtCreator normally compiles the code in a separate
directory. For example, in my case the project directory was
/home/olaf/Hello and the build directory
/home/olaf/build-Hello-Desktop-Debug. AspectC++ has the notion of the
"project" (see -p option in the documentation). The assumption is that
all files stored in the directory tree of the "project" are AspectC++
code while all other files are included libraries written in normal C++.
AspectC++ keywords, such as 'aspect', 'pointcut', etc., are only
regarded as keywords if they are located in a file in the project tree.
However, the default setting for -p in ag++ is "-p .". As a consequence,
when QtCreator compiles your code, the project tree -- from the ac++
perspective -- is the build directory and not the source directory.

In order to work around this problem, I changed my .pro file slightly:

---
CONFIG += qt acxx
QT       += core gui
ASPECT_HEADERS += ../Hello/aspect.ah
QMAKE_ACXX_FLAGS += -p . -p ../Hello

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
...
---

With the QMAKE_ACXX_FLAGS we now have a project that has *two*
directories: "." (the build directory) and "../Hello" (the source
directory).

The "../Hello/" in front of aspect.ah was needed to by make and ag++ to
find the aspect header.

I hope this helps for you, too! My Qt version is 5.6.2.

acxx.prf is really simplistic. It was just a "proof of concept". If
anyone has a more robust implementation, which can deal with separate
build directories -- ideally also with directory hierarchies -- let me
know, please. I'd be happy to update our old instructions from 2011.

Best regard,

Olaf


More information about the aspectc-user mailing list