In this paper, an efficient formulation for the topology optimization of extruded beams is developed considering linearized buckling, displacement, and stress constraints. The proposed method relies on a computationally efficient extended\generalized finite element (XFEM\GFEM) formulation for the forward problem, recently developed for the analysis of beams. In this method, a coarse 3D finite element (FE) mesh is enhanced with global enrichment functions, enabling a substantial reduction in the number of degrees of freedom with comparable accuracy to a traditional 3D FE fine mesh. The material distribution at the cross-section is optimized utilizing the material density approach with the Solid Isotropic Material with Penalization (SIMP) method. Our objective is to minimize the total weight of the beam, subject to performance constraints including buckling, displacement, and stress. The forward problem enables the application of general loading and boundary conditions. Thus, both buckling and lateral–torsional buckling are automatically considered. The optimization problem is solved using a gradient-based optimization approach, with analytical gradients derived by using the adjoint variable method. Several numerical examples are presented to investigate the accuracy and efficiency of the proposed formulation. A parametric study showed that the optimized cross-section is strongly dependent on the length and permissible buckling load. In addition, it is shown that a simultaneous formulation leads to significantly different designs, with different structural behavior, compared to results obtained by considering only a subset of the performance constraints. Finally, we verify the model on a beam warping problem under pure torsion, in which the cross-section optimization converges to a known analytical solution. Compared with traditional FEM, two orders of magnitude in terms of execution time are reported in favor of the proposed XFEM\GFEM approach. • A new approach for the topology optimization of extruded beams is proposed. • The forward problem is solved using an efficient numerical scheme relying on the extended finite element method. • The approach simultaneously considers buckling, stress, and displacement constraints. • We show that the beam's length significantly affects the optimal shape. • The proposed XFEM\GFEM approach shows significant time savings compared with 3D FE. [ABSTRACT FROM AUTHOR]