Establish VPN-Connection by running an App



I have built a custom yocto with openvpn in it. I can establish an connection through the terminal by executing openvpn.
What is the best way to establish an openvpn connection inside of my app?

For example, after an internet connection is established, I would do the following:
popen("/usr/sbin/openvpn /etc/openvpn/client.conf", "r");

This works more or less. Openvpn is being executed, by no connection can be established. I get the output

RESOLVE: Cannot resolve host address: Name or service not known
(Address was replaced by “” for this post).

But if the app is still running, I can establish a connection through the normal terminal again by executing the same command like in the c application.

Has anyone an idea where there could be the problem or how I should establish an vpn connection?