Gstreamer linking failed tsdemux and h264parse

GstElement *_gst_demux = gst_element_factory_make (“tsdemux”, NULL);
GstElement *_gst_parse = gst_element_factory_make (“h264parse”, NULL);
GstElement *_gst_pipeline = gst_pipeline_new (“test-pipeline”);
gst_bin_add_many (GST_BIN (_gst_pipeline), _gst_demux, _gst_parse, NULL);
gst_element_link (_gst_demux, _gst_parse);

gst_element_link returns 0.

However the following pipe works:

gst-launch-1.0 udpsrc port=51002 ! tsdemux ! h264parse ! omxh264dec ! nv3dsink sync=false

The other elements can be linked without error in the code. How can I successfully link tsdemux and h264parse from my c++ code?

I found the answer here: