Repository: bitcoin/bitcoin (language: cpp)

Issue:
Building a wallet with legacy support fails on OpenBSD 7.4
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

Building a wallet with legacy support by following the instructions located within `doc/build-openbsd.md` fails on OpenBSD 7.4 (the latest OpenBSD release).

The instructions fail during the `gmake` step from the **Legacy Wallet Support** section.

My understanding is that this project used to install BerkeleyDB support via a (now removed) installer script. The removed installer script `contrib/install_db4.sh` was removed in [this commit](https://github.com/bitcoin/bitcoin/commit/44f3c7de21fd86343a2427d2e864ea2001499c5e). It seems the intent moving forward is to build BerkeleyDB from the `depends` folder - this process is currently failing - hence the creation of this issue.

### Expected behaviour

A successful build of a wallet with legacy support is possible by strictly following the instructions found within `doc/build-openbsd.md` and `depends/README.md`.

### Steps to reproduce

```
$ pkg_add bash git gmake libevent libtool boost
$ pkg_add autoconf automake python
    17: autoconf-2.71
    10: automake-1.16.5
    4: python-3.11.5
$ git clone https://github.com/bitcoin/bitcoin.git
$ cd bitcoin
$ git checkout v25.1
$ pkg_add gtar
    1: gtar-1.35
    (per instructions on https://github.com/bitcoin/bitcoin/tree/master/depends/README.md)
$ gmake -C depends NO_BOOST=1 NO_LIBEVENT=1 NO_QT=1 NO_SQLITE=1 NO_NATPMP=1 NO_UPNP=1 NO_ZMQ=1 NO_USDT=1
```

### Relevant log output

Failure Output
```
[REMOVED]
config.status: executing libtool commands
Building bdb...
[REMOVED]
In file included from ../dist/./../cxx/cxx_db.cpp:13:
./db_cxx.h:59:10: fatal error: 'iostream.h' file not found
#include <iostream.h>
         ^~~~~~~~~~~~
1 error generated.
[REMOVED]
```

Installed Packages
```
$ pkg_info -m
autoconf-2.71       automatically configure source code on many Un*x platforms
automake-1.16.5     GNU Standards-compliant Makefile generator
bash-5.2.15         GNU Bourne Again Shell
boost-1.80.0p2v0    free peer-reviewed portable C++ source libraries
git-2.42.0          distributed version control system
gmake-4.4.1         GNU make
gtar-1.35           GNU version of the traditional tape archiver
libevent-2.1.12p0   event notification library
libtool-2.4.2p2     generic shared library support script
python-3.11.5       interpreted object-oriented programming language
quirks-6.160        exceptions to pkg_add rules and cache
```

### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

v25.1

### Operating system and version

OpenBSD 7.4 amd64

### Machine specifications

_No response_


Discussion / hints:
I don't have OpenBSD, so I can't help here. However, it may be possible to undo the commit that removed `install_db4.sh`, or otherwise restore the script and use it (at your own risk). Longer term, it is recommend to move toward sqlite descriptor wallets.
> In file included from ../dist/./../cxx/cxx_db.cpp:13:
> ./db_cxx.h:59:10: fatal error: 'iostream.h' file not found

The issue is some code like this in bdb:
```cpp
#ifdef HAVE_CXX_STDHEADERS
#include <iostream>
#include <exception>
#define	__DB_STD(x)	std::x
#else
#include <iostream.h>
#include <exception.h>
#define	__DB_STD(x)	x
#endif
```

For some reason, configure fails to detect C++ header availability, and `HAVE_CXX_STDHEADERS` is not defined. Is `g++` and a C++ standard library definitely available, which version?

Are you able to post the output of `config.log` from the bdb build in depends? That should show why the configure check fails to detect the c++ headers. You can get that output using:
```bash
gmake -C depends bdb_configured
cat depends/work/build/your-build-triplet/bdb/4.8.30-somehash/build_unix/config.log
```

Fix patch:
diff --git a/depends/packages/bdb.mk b/depends/packages/bdb.mk
index 9f5a925015b0e..1a21238152ad5 100644
--- a/depends/packages/bdb.mk
+++ b/depends/packages/bdb.mk
@@ -17,7 +17,6 @@ $(package)_config_opts_android=--with-pic
 $(package)_cflags+=-Wno-error=implicit-function-declaration -Wno-error=format-security -Wno-error=implicit-int
 $(package)_cppflags_freebsd=-D_XOPEN_SOURCE=600 -D__BSD_VISIBLE=1
 $(package)_cppflags_netbsd=-D_XOPEN_SOURCE=600
-$(package)_cppflags_openbsd=-D_XOPEN_SOURCE=600
 $(package)_cppflags_mingw32=-DUNICODE -D_UNICODE
 endef
 


Test patch: