Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
NebulaFox
Posts: 4
Registered: ‎02-20-2013
My Device: Z10

moc rule in Makefile not working

I am trying to make a shared library. I used the Blackberry Project -> Shared Library and went for the Makefile option. The source files and header files are being compiled and included. The hard part is getting the moc to work.

 

Here is my Makefile:

LIST=CPU
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

MOC := /Applications/bbndk/host_10_0_9_534/darwin/x86/usr/bin/moc

SRC+=moc_file.cpp

moc_%.cpp: %.h
	$(MOC) $(DEFINES) $(INCVPATH) $< -o $@

 The project contains a src directory and a public directory. The src directory contains headers and source files and the public directory contains public headers. I have modified the common.mk to include these in the EXTRA_SRCVPATH.

 

My basic assumption is that when make goes looking for moc_file.cpp it would read the rules and realise moc_file.cpp can be created from file.h with the moc command, but this cannot be the case as I continuously get the error No rule to make target `moc_file.o', needed by libry.a. So how does it really work and how can I fix this?

Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: moc rule in Makefile not working

do you have moc_file.cpp successfully created by moc based on file.h?

It seems in your case make can't find a rule to create moc_file.o file based on your moc_file.cpp

New Contributor
NebulaFox
Posts: 4
Registered: ‎02-20-2013
My Device: Z10

Re: moc rule in Makefile not working

The moc_file.cpp appears not to be created at all.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: moc rule in Makefile not working

That's the problem. I am afraid 'Shared library' type of project is not considered by NDK as 'Cascades-like' project so new project does not know that it needs to run moc on .h files containing Q_OBJECT. I'd look on how ordinary Cascades project handles this and added the same to your makefiles.

New Contributor
NebulaFox
Posts: 4
Registered: ‎02-20-2013
My Device: Z10

Re: moc rule in Makefile not working

That's what I would hope to do by adding this

 

SRC+=moc_file.cpp

moc_%.cpp: %.h
	$(MOC) $(DEFINES) $(INCVPATH) $< -o $@

 by adding the moc_file.cpp to the SRC macro, I'd hope that make would see this file does not exist and call the rule, but it doesn't. Then there is this rule

 

MOC_MODULES := $(patsubst %.h, moc_%, $(shell grep -l Q_OBJECT *.h))

 

that could be used to find the files that do contain Q_OBJECT but sadly *.h always thorws up an error saying that  

grep: *.h: No such file or directory.

New Contributor
NebulaFox
Posts: 4
Registered: ‎02-20-2013
My Device: Z10

Re: moc rule in Makefile not working

Just realised why I get the error. There are no headers because they are in the src and public folder. If I replace *.h with $(INCVPATH)/*.h that find all the headers - as long as INCVPATH is set up correctly in common.mk.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: moc rule in Makefile not working

So, fixed?

Regular Contributor
robinhuang
Posts: 52
Registered: ‎02-08-2013
My Device: Z10

Re: moc rule in Makefile not working

Anybody knows how to run moc if using CDT internal builder in project?