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.
A few quick thoughts on this:
1. 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 2. 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 3. 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 directives
CAUTION: 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!
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
On 23.07.25 19:08, Ben Kaufman via sr-users wrote:
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 directives CAUTION: 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!
The solution was to add one more line at the end.
I'm still learning and not yet confident enough to write configs on my own, but as I gain more experience, I’ll definitely keep the advice in mind about using simpler and more robust configurations.
Thank you!
On Jul 23, 2025, at 1:08 PM, Ben Kaufman via sr-users sr-users@lists.kamailio.org wrote:
• 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.
+1!
My configs got far simpler and more legible once I conquered my fear of committing to hard code paths and stopped adding unnecessary cleverness.
-- Alex
-- Alex Balashov Principal Consultant Evariste Systems LLC Web: https://evaristesys.com, https://www.csrpswitch.com Tel: +1-706-510-6800
If you havea need for multiple scripts, i.e different boxes, then write multiple scripts. If you only have a single type of box then us if statements to call the various components needed depending on the traffic type. I'm not sure why you would need to define multiple directives either.
it appears you have nested some too, whynot just rewrite the scriptto have various routes instead of all these directives and control the flow based on the message type.
I'm assuming most of these directives will be set to TRUE.
Regards,
Richard
On 23/07/2025 20:41, Giovanni Maruzzelli via sr-users wrote:
On Wed, Jul 23, 2025, 21:14 Alex Balashov via sr-users sr-users@lists.kamailio.org wrote:
My configs got far simpler and more legible once I conquered my fear of committing to hard code paths and stopped adding unnecessary cleverness.
+1
-giovanni
Kamailio - Users Mailing List - Non Commercial Discussions --sr-users@lists.kamailio.org To unsubscribe send an email tosr-users-leave@lists.kamailio.org Important: keep the mailing list in the recipients, do not reply only to the sender!
Try add one mandatory route block like
route{ ; }
On Wed, 2025-07-23 at 16:48 +0000, Fernando Lopes via sr-users wrote:
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!