The density-dependent finite-range Gogny force has been used to derive the effective Hamiltonian for the shell-model calculations of nuclei. The density dependence simulates an equivalent three-body force, while the finite range gives a Gaussian distribution of the interaction in the momentum space and hence leads to an automatic smooth decoupling between low-momentum and high-momentum components of the interaction, which is important for finite-space shell-model calculations. Two-body interaction matrix elements, single-particle energies and the core energy of the shell model can be determined by the unified Gogny force. The analytical form of the Gogny force is advantageous to treat cross-shell cases, while it is difficult to determine the cross-shell matrix elements and single-particle energies using an empirical Hamiltonian by fitting experimental data with a large number of matrix elements. In this paper, we have applied the Gogny-force effective shell-model Hamiltonian to the ${it p}$- and ${it sd}$-shell nuclei. The results show good agreements with experimental data and other calculations using empirical Hamiltonians. The experimentally-known neutron drip line of oxygen isotopes and the ground states of typical nuclei $^{10}$B and $^{18}$N can be reproduced, in which the role of three-body force is non-negligible. The Gogny-force derived effective Hamiltonian has also been applied to the cross-shell calculations of the ${it sd}$-${it pf}$ shell.