Just for the records, "kamailio --cfg-print" should not show any preprocessor directives, it should plain text with the preprocessor directive/conditions evaluated, but its output should help identifying when some preprocessor directive is set to a wrong value or misplaced/missing.
Then, is the last #!endif on the last line without a new line after it? If yes, add a new line after it, the parser might not see it otherwise (although I thought was addressed at some point, it might be only my hope it happened).
Cheers,
Daniel
A few quick thoughts on this:
Preprocessor definitions can begin with either#!
OR!!
so you might want to use this as your grep regex (I didn't test this, but i think it would catch both patterns):[#!]!ifn?def|[#!]!endif You mention that you have a definitions.cfg file which means that you're using at least one include_file or import_file declaration, and if you're using one, then it's a good chance you're using more than one. Make sure you're considering your entire Kamailio config file. Rather than grepping only kamailio.cfg it might be more helpful to dump the kamailio config to grep:kamailio --cfg-print | grep [#!]!ifn?def|[#!]!endif Finally it might be good to consider if you need all of those preprocessor defines and ifdefs. Yes, the default sample config has many of them, but that's a situation where a single file is meant to be able to illustrate a lot of potential use cases. In most real-world situations, you will program the server already knowing what you will/wont need and not need all of those feature flags. Like, either my environment has RTPEngine and I'm going to use it, or it doeesn't. I know this when I write my Kamailio scrip, so either I write the code I need or I don't. It's likely that you can clean these up, resolve your issue, and have the benefit of a cleaner more easier read config as well.
Regards,Kaufman
From: Fernando Lopes via sr-users <sr-users@lists.kamailio.org>
Sent: Wednesday, July 23, 2025 11:48 AM
To: sr-users@lists.kamailio.org <sr-users@lists.kamailio.org>
Cc: Fernando Lopes <fernandolopes20003@gmail.com>
Subject: [SR-Users] Error: different number of preprocessor directivesCAUTION: This email originated from outside the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Hello everyone,
I'm having an issue with my Kamailio config where I'm getting the following error:
ERROR: bad config file (0 errors) (parsing code: 0)
0(2) ERROR: <core> [core/ppcfg.c:276]: pp_ifdef_level_error(): different number of preprocessor directives: 1 more #!if[n]def as #!endif
I've gone through the config up and down so many times and can't seem to find the problem. I have a definitions.cfg file where I define all the variables, and I’ve made sure that every #!ifdef WITH_SOMETHING has a corresponding definition.
I also ran this command (recommended by GPT):
grep -E '#!ifn?def|#!endif' /usr/local/etc/kamailio/kamailio.cfg
It shows matching numbers of #!ifdef and #!endif, and I’ve checked it manually several times — everything looks fine.
Any tips for debuging or finding the problem.
#!ifdef WITH_CDRS
#!endif
#!ifdef WITH_DEBUG
#!endif
#!ifdef WITH_TLS
#!endif
#!ifdef WITH_NAT
#!endif
#!ifdef WITH_TLS
#!endif
#!ifdef WITH_FAIL2BAN
#!ifdef WITH_ANTIFLOOD
#!endif
#!endif
#!ifdef WITH_DISPATCHER
#!endif
#!ifdef WITH_RESPONSE_STATS
#!endif
#!ifdef WITH_HOMER
#!endif
#!ifdef WITH_CDRS
#!endif
#!ifdef WITH_RTPENGINE
#!endif
#!ifdef WITH_HTTP
#!endif
#!ifdef WITH_WEBSOCKETS
#!endif
#!ifdef WITH_NAT
#!ifdef WITH_RTPENGINE
#!endif
#!endif
#!ifdef WITH_TLS
#!endif
#!ifdef WITH_ANTIFLOOD
#!endif
#!ifdef WITH_FAIL2BAN
#!endif
#!ifdef WITH_DISPATCHER
#!endif
#!ifdef WITH_HOMER
#!endif
#!ifdef WITH_CDRS
#!endif
#!ifdef WITH_FAIL2BAN
#!endif
#!ifdef WITH_RTPENGINE
#!endif
#!ifdef WITH_HOMER
#!endif
#!ifdef WITH_RTPENGINE
#!endif
#!ifdef WITH_ANTIFLOOD
#!endif
#!ifdef WITH_NATSIPPING
#!endif
#!ifdef WITH_NOAUTH_PRIVATE_NET
#!endif
#!ifdef WITH_AUTH
#!endif
#!ifdef WITH_NAT
#!endif
#!ifdef WITH_NAT
#!endif
#!ifdef WITH_NAT
#!endif
#!ifdef WITH_RTPENGINE
#!endif
#!ifdef WITH_DISPATCHER
#!endif
#!ifdef WITH_WEBSOCKETS
#!endif
#!ifdef WITH_HTTP
#!ifdef WITH_WEBSOCKETS
#!endif
#!endif
#!ifdef WITH_RTPENGINE
#!endif
Thank you.
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions -- sr-users@lists.kamailio.org
To unsubscribe send an email to sr-users-leave@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the sender!
__________________________________________________________ Kamailio - Users Mailing List - Non Commercial Discussions -- sr-users@lists.kamailio.org To unsubscribe send an email to sr-users-leave@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender!
-- Daniel-Constantin Mierla (@ asipto.com) twitter.com/miconda -- linkedin.com/in/miconda Kamailio Consultancy, Training and Development Services -- asipto.com