In this paper, we aim to develop a technology that can be commonly used for link mechanisms. We use nonlinear model predictive control to design a control system that enables trajectory generation and trajectory tracking using only a single controller. By using the nonlinear model predictive control, we can expect the versatility that does not depend on the hardware by changing the model, the scalability that can realize multiple objectives by the evaluation function, and the easiness that the trajectory generation and tracking can be realized by a single controller. As an example of a link mechanism, a hydraulic excavator was modeled as a link mechanism with four degrees of freedom, and the effectiveness of the proposed method was verified by numerical simulation. In this simulation, the hydraulic excavator performed the loading operation to load the excavated soil into the dump truck and the repositioning operation to move to the next excavation position. During these operations, the excavator needs to reach the target position while avoiding collision with the dump truck. From the simulation results, it was confirmed that by setting the evaluation function appropriately, the loading and repositioning operation in three-dimensional space can be performed while avoiding collision with obstacles without giving a target trajectory.